Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Anybody good with math?
#1
If i have two positions [x1,y1] and [x2,y2], now lets say that [x1,y1] is the center of a circle and i want the angle on a straight line from [x1,y1] to [x2,y2]..
Got it?

But one more thing, i know i'm wrong but i want 0 degrees to point upwards and 90 to the right etc. etc.

Thx
ttp://hem.passagen.se/qb.basta
Reply
#2
Quote:If i have two positions [x1,y1] and [x2,y2], now lets say that [x1,y1] is the center of a circle and i want the angle on a straight line from [x1,y1] to [x2,y2]..
Got it?

what do you mean by 'the angle on a straght line' I guess it doesn't quite make sense. so what you're saying is
(for instance)

x1 = 50
y1 = 50

x2 = 100
y2 = 100

'and you want an 'angle on a straght line' between x1 and y1

line (x1,y1)-(x2,y2)

or what? If this is incorrect, please elaborate the question.
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#3
Okey.. think of [x1,y1] as the center of a circle and [x2,y2] as a point on the edge.. Now line (x1,y1)-(x2,y2) is the radius (don't know you spell it like that) now i want the lines angle..
ttp://hem.passagen.se/qb.basta
Reply
#4
ordinarily you'd calculate the length of the small, outer side, and one of the radii.

Then use cos = adj/hyp. (I think)

2pi = 360 deg
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#5
Sir:
The norm for positive angle measurement is CCW rotation starting from the right of the arc center, and going around to the left. Thus zero radians exists at the start point (exactly right of center), PI/2 radians is directly above the circle center, PI radians is exactly left of center, etc. Referring to the face of a clock, 3 o'clock is 0 (zero), 12 o'clock is PI/2, 9 o'clock is PI ---.
In calculating the angle, ATAN (arctangent) is used. That is
Theta (the angle) = ARCTAN Y/X
Now one must recall that the signs of Sine, Cosine, Tangent vary according to the sequence ASTC;

In the first quadrant, 3 o'clock to 12 o'clock (going CCW) ALL (A) are positive;
In the second quadrant (12 to 9 o'clock) SINE (S) is positive;
In the third quadrant (9 to 6 o'clock) TANG (T) is positive;
In the fourth quadrant (6 ccw to 3 o'clock) COS © is positive.

You will need to use a bit of geometry to get the non-standard results you want. If you're still in doubt, I can help more as I use this a lot in my machine controller.
Regards,
Jack C.
Reply
#6
Quote:Okey.. think of [x1,y1] as the center of a circle and [x2,y2] as a point on the edge.. Now line (x1,y1)-(x2,y2) is the radius (don't know you spell it like that) now i want the lines angle..

You want the "line's angle" with respect to *what* reference line? However, your initial indication that you want 0 degrees to be the upwardly vertical line may fill in that blank. I assume that your xy coordinates are in the screen's coordinate system where y is downwards and x is to the right and that you want the clockwise angle from the upwardly vertical (-y) axis. First get the angle the (x1,y1) - (x2,y2) line segment makes with the x-axis and then add PI/2 to that angle. (First get PI).

PI = 4*ATN(1)
'
' Watch out for special case.
'
ANGLE = (PI/2)*SGN(Y2-Y1)
IF X1 <> X2 THEN ANGLE = ATN((Y2 - Y1) / (X2 - X1))
'
' Make sure quadrant is right.
'
IF X2 - X1 < 0 THEN ANGLE = ANGLE + PI
'
' Shift reference.
'
ANGLE = ANGLE + PI/2
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#7
Here's a function:

Code:
FUNCTION Rel.Angle% (X1, Y1, X2, Y2)
'By RelSoft of Auraflow
'Parameters:
'x1,y1= the starting coord
'x2,y2=the target coord
'Returns=the Angle in degrees between the two coords
'useable with SIN and COS so this is useful for calculating the
'vectors between 2 points.
'This is the Fast BASIC version

'Rad=Deg*PI/180
'Rad*180=Deg*PI
'Rad*180/PI=Deg
'Deg=Rad*180/PI

IF X1 = X2 THEN
IF Y1 < Y2 THEN
Rel.Angle% = 90
EXIT FUNCTION
ELSEIF Y1 > Y2 THEN
Rel.Angle% = 270
EXIT FUNCTION
ELSE
Rel.Angle% = 0
EXIT FUNCTION
END IF
ELSE
   DeltaX = X2 - X1
   DeltaY = Y2 - Y1
   AngleTemp% = ATN(DeltaY / DeltaX) * 180 / 3.141593
   AngleTemp% = AngleTemp% + 90
IF X1 > X2 THEN
   AngleTemp% = AngleTemp% + 180
END IF
END IF
   AngleTemp% = AngleTemp% - 90
IF AngleTemp% < 0 THEN AngleTemp% = AngleTemp% + 360
   Rel.Angle% = AngleTemp%

END FUNCTION

For an ASM version just shout!!!!

:*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#8
SHOUT!

LoL
Reply
#9
Here:

http://relsoft.wrq.cjb.net/files/RelLibV3.2.zip

Check RelAngle out.... :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#10
Thx everyone!
I have time to check it all on friday..
ttp://hem.passagen.se/qb.basta
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)