trigonometry problem

BlitzMax Forums/BlitzMax Beginners Area/trigonometry problem

hub(Posted 2010) [#1]
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


GfK(Posted 2010) [#2]
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


hub(Posted 2010) [#3]
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


GfK(Posted 2010) [#4]
could you explain more Angle = ATan2(InitY - ePosY, InitX - ePosX) ?
is there a way to use initx and inity also to compute d# ?
Um... maybe but why bother since you already know the global position of both points?


hub(Posted 2010) [#5]
i've just adapted this to my project and all works fine now ! Many thanks for your help !