AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need help with a Math-Function

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Rubberduck



Joined: 24 Apr 2005
Posts: 96

PostPosted: Fri Apr 29, 2005 3:33 pm    Post subject: Need help with a Math-Function Reply with quote

What I want to do is the following:

If want to have a function with the following parameters:

MidX,MidY <== The center of a circle
angle <== a angle (1..360) where 0 and 360 are North
radius <== the radius of the circle
ByRef Tx, ByRef Ty <== those values are the results of the function

Here my little testscript:

Code:

;/// Build up a little Gui for the script
gui, color, FFFFFF
gui, add, text, x10 y10,*** Circle Test ***
gui, add, button, x10 y30,Circle Test
gui, add, button, x10 y60,Quit Script
gui, show

GetPointRelative(MidX,MidY,angle,radius,Byref Tx, Byref Ty)
{
   PI = 3,1415926535897932384626433832795
   PI_1 = 2*PI

   ;//I think there must be some calculation like in the next lines
   Transform, SinVal, Sin, %angle%
   Transform, CosVal, Cos, %angle%
   Tx:=MidX+(SinVal*radius)
   Ty:=MidY-(CosVal*radius)

   MsgBox, In_XY: %MidX%/%MidY% In_Angle: %angle% In_Radius: %radius%`n`n%Tx%/%Ty%
   return
}

ButtonCircleTest:
  Tx = 0
  Ty = 0
  GetPointRelative(300,300,90,100,Tx,Ty)
return

ButtonQuitScript:
exitapp


My problem is, I am a absolute Math-Idiot.

Here some values that should be the right result (I hope I calculated right;)

GetPointRelative(50,50,0,100,Tx,Ty) => Tx=50 Ty=-50
GetPointRelative(50,50,90,100,Tx,Ty) => Tx=150 Ty=50
GetPointRelative(50,50,180,100,Tx,Ty) => Tx=50 Ty=150
GetPointRelative(50,50,270,100,Tx,Ty) => Tx=-50 Ty=50

The function should of course work with angle-values like 32,345...
or even negative angle-values. Also the function should work
with angle-values like 1876 which must be lowered to 76 first.

I know that sin and cos works with radians, so that there must be
included some degtorad-Function. But I don't succeded with any tries
I did.

Please can someone help with this function ?
_________________
Wer keine Antworten hat muss nicht dumm sein,
dumm ist nur der welcher keine Fragen hat.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Fri Apr 29, 2005 4:40 pm    Post subject: Reply with quote

Try this
Code:
InputBox x, MidX, X-coordinate of Center,, 160, 140
InputBox y, MidY, Y-coordinate of Center,, 160, 140
InputBox r, Radius, Radius of Circle,, 160, 140
InputBox a, Radius, Angle in degrees,, 160, 140

GetPointRelative(x,y,a,r,Tx,Ty)
MsgBox, In_XY: %x%/%y% In_Angle: %a% In_Radius: %r%`n`n%Tx%/%Ty%

GetPointRelative(MidX,MidY,angle,radius,Byref Tx, Byref Ty)
{
   Transform SinVal, Sin, % angle*0.01745329252
   Transform CosVal, Cos, % angle*0.01745329252
   Tx := MidX - SinVal*radius
   Ty := MidY + CosVal*radius
}
The angle is measured in degrees, from North, counterclockwise. (Use decimal points, not commas; conversion from angle to radians are done by multiplying with pi/180 = 0.01745329252.) You might have to change the InputBox size. It looks nice on my 1600x1200 pixel screen.
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1186
Location: switzerland

PostPosted: Fri Apr 29, 2005 7:25 pm    Post subject: Reply with quote

this script not solved your problem
just an idea for input
Code:
;calculate.ahk  2005-04-03 garry
;----WINDOW
Gui, Show, x270 y110 h280 w485, CALCULATE
;----TITLE
Gui, Font,  S12 CDefault Bold, Verdana
Gui, Add, Text, x186 w140 h30, EXAMPLE-1
;----INPUTS VARIABLE
Gui, Font,  S10 CDefault Bold, Verdana
Gui, Add, Text, x100 y80 w120 h20, INPUT A=
;Gui, Add, Edit, number limit2  x176 y80 w240 h20 vA         ;example with number limit (here 2 digits)
Gui, Add, Edit, x176 y80 w240 h20 vA
Gui, Add, Text, x100 y120 w120 h20, INPUT B=
Gui, Add, Edit, x176 y120 w240 h20 vB

;RESULT output window
Gui, Add, Text, x10 y160 w160 h20, RESULT1  C=(A+B)
Gui, Add, Text, x10 y200 w160 h20, RESULT2  D=(A*B)
Gui, Add, Edit, x176 y160 w240 h20 ReadOnly vC,
Gui, Add, Edit, x176 y200 w240 h20 ReadOnly vD,
Gui, Add, Button, x340 y240 w40 h20, CLR
Gui, Add, Button, x420 y240 w40 h20, OK
Return

ButtonOK:
Gui, Submit, NoHide
C := A+B
D := A*B
GuiControl, , C, %C%
GuiControl, , D, %D%
return

ButtonCLR:
A=
B=
C=
D=
splashtexton,,,%A%
splashtextoff
splashtexton,,,%B%
splashtextoff
splashtexton,,,%C%
splashtextoff
splashtexton,,,%D%
splashtextoff
GuiControl, , A, %A%
GuiControl, , B, %B%
GuiControl, , C, %C%
GuiControl, , D, %D%
;or just use reload
;reload
return

GuiClose:
ExitApp
ESC::EXITAPP
Back to top
View user's profile Send private message
Rubberduck



Joined: 24 Apr 2005
Posts: 96

PostPosted: Sat Apr 30, 2005 12:28 am    Post subject: Thanks Reply with quote

Thanks for the Quick Support to both of you. Laughing Very Happy Smile Surprised

I try the scripts. I need them for my Zuma-Solver.
My Zuma-Solver is nearly finished.
I put it in the Scripts-Sektions if it is ready.

Edit: @Laszlo; Great work, thank. Have you studied Maths ?? Question
_________________
Wer keine Antworten hat muss nicht dumm sein,
dumm ist nur der welcher keine Fragen hat.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group