trigonometry problem
BlitzMax Forums/BlitzMax Beginners Area/trigonometry problem
| ||
i trying to kill a logic bug into my project. why the green square is not at the good location : PosX = ePosX + InitX PosY = ePosY + InitY when the program start ? so how to compute the true angle when i start the program ! Thanks ! Last edited 2010 |
| ||
I don't understand what you're asking. What do you mean by "is not at the good location"? Where do you expect the green square to be? [edit] Is this what you mean? Strict Graphics 800,600 Local ePosX# Local ePosY# Local PosX# Local PosY# Local InitX# Local InitY# Local Angle# = 30 ePosX# = 100 ePosY# = 100 InitX = -50 InitY = -50 PosX = ePosX + InitX PosY = ePosY + InitY Angle = ATan2(InitY - ePosY, InitX - ePosX) While Not KeyDown(KEY_ESCAPE) Cls Local d# = Sqr((ePosY-PosY)*(ePosY-PosY) + ((ePosX-PosX)*(ePosX-PosX))) DebugLog d PosX = ePosX + Cos(Angle) * d 'd# PosY = ePosY + Sin(Angle) * d 'd# SetRotation angle SetColor 255,0,0 DrawRect ePosX-10,ePosY-3,20,20 SetColor 0,255,0 DrawRect PosX-10,PosY-3,20,20 If KeyDown (KEY_DOWN) Then Angle# = Angle# + 1.0 If KeyDown (KEY_UP) Then Angle# = Angle# - 1.0 Angle = (Angle + 360) Mod 360 SetRotation 0 SetColor 255,255,255 DrawText angle,0,0 Flip Wend [edit again] In case anybody thinks I've gone mental for setting the value of Angle in its declaration, then changing it later - my code is a modified version of what was posted originally! Last edited 2010 |
| ||
could you explain more Angle = ATan2(InitY - ePosY, InitX - ePosX) ? is there a way to use initx and inity also to compute d# ? Last edited 2010 |
| ||
could you explain more Angle = ATan2(InitY - ePosY, InitX - ePosX) ? Um... maybe but why bother since you already know the global position of both points? is there a way to use initx and inity also to compute d# ? |
| ||
i've just adapted this to my project and all works fine now ! Many thanks for your help ! |