Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
angles
#1
I need to know how to find the angle between two points. I've been told that cross products do this, but I don't have any idea what those are. Can anyone help?
PY is done
Reply
#2
Could you perhaps be a little more specific?
At this moment I can't give you much more advice than to look up
trigonometry.
/post]
Reply
#3
sounds like you need ATN
[Image: freebasic.png]
Reply
#4
well, you could get the distance

Code:
d! = SQR((x2! - x1!) ^ 2 + (y2! - y1!) ^ 2)

and check it against all angles, but this is indeed very time consuming, and a waste of memory, but you can optimize it but compating point one's (x1, y1) position against point two's - if x1 < x2, then it will be somewhere between 180 and 360 (left side), and if it's above, you can assume that it's only between 270 and 360.

this method is very time consuming, still....but i don't know any other ones off hand

Oz~
Reply
#5
Here is a way to do it, the REMs explian each part... :

[syntax="qbasic"]X01 = 10: Y01 = 10' Point 1
X02 = 40: Y02 = 40' Point 2

'Sort and find distance across
IF X02 > X01 THEN XR01 = X02 - X01
IF X02 < X01 THEN XR01 = X01 - X02

'Sort and find distance up
IF Y02 > Y01 THEN YR01 = Y02 - Y01
IF Y02 < Y01 THEN YR01 = Y01 - Y02

'Use distances to return angle in Radins
RAD! = ATN(YR01 / XR01)
'Convert radins to degrees
ANG! = (RAD! / 3.1415926535897932384626433832795 * 180)

PRINT ANG![/syntax]

Making that a SUB routine might be better if you intend to use it allot.. :wink:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#6
You can't get an angle between 2 points. That's just big nonsense.

Sorry just had to say this.

It's too late for me to post any easy vector code that might help.

Btw Rattrap:
You forgot to check whether XR01 is zero.
Btw...
Code:
IF X02 > X01 THEN XR01 = X02 - X01
twice looks worse than just
Code:
XR01 = Abs(X02 - X01)
Also, using that many digits of PI is a bit overdoing... it wont even fit in a Single.
Reply
#7
Hmm.... :oops:

This work better?

Code:
X01 = 10: Y01 = 10' Point 1
X02 = 40: Y02 = 40' Point 2

'Sort and find distance across
XR01 = ABS(X01 - X02)

'Sort and find distance up
YR01 = ABS(Y01 - Y02)

'Use distances to return angle in Radins
IF XR01 <> 0 THEN
    RAD! = ATN(YR01 / XR01)
ELSE
    IF YR01 > 0 THEN RAD! = (90 * 3.1415926 / 180)
    IF YR01 = 0 THEN RAD! = 0
END IF
'Convert radins to degrees
ANG! = (RAD! / 3.1415926 * 180)

PRINT ANG!
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#8
Quote:I need to know how to find the angle between two points. I've been told that cross products do this, but I don't have any idea what those are. Can anyone help?

Atan2.

Cross product does not return the angle it returns a vector orthogonal to a plane.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#9
Or use the vector identity

a . b = a . b . cos α

In which α is the angle between the two vectors.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)