SRL Archive - Help and Support

Math HELP!


n3ss3s

2007-11-18 08:09:36

Well I am trying to make a function that calculates the angle of a point from a point.

Like XX, YY, OriginX, OriginY.

What I have so far:


program New;
Var
ASArray, ACArray: TExtendedArray;

Procedure LoadArcSinArray;
Var
I: Integer;
Begin
SetArrayLength(ASArray, 360);
For I := 0 To 359 Do
Begin
ASArray[i] := ArcSin(Sin((I / 180) * Pi));
Writeln('AS: '+IntToStr(i)+' : '+FloatToStr(ASArray[i]));
End;
End;

Procedure LoadArcCosArray;
Var
I: Integer;
Begin
SetArrayLength(ACArray, 360);
For I := 0 To 359 Do
Begin
ACArray[i] := ArcCos(Cos((I / 180) * Pi));
Writeln('AC: '+IntToStr(i)+' : '+FloatToStr(ACArray[i]));
End;
End;

Procedure InFloatArrayEx(E: Extended; EA: TExtendedArray; Var Where: Integer);
Var
I: Integer;
Begin
For I := 0 To High(EA) Do
Begin
If E = EA[i] Then
Begin
Where := I;
Exit;
End;
End;
End;

Function AngleOf(xx, yy, ox, oy: Integer): Integer;
Var
A, I, R: Integer;
Begin
R := Distance(xx, yy, ox, oy);

End;

begin
LoadArcCosArray;
LoadArcSinArray;
end.



Its like XX = Ox + Radius * Cos(Radians(Angle - 90))

and I want to find out the angle, does somebody understand what I am trying to say?

Help appreciated a lot!

Miitchyy

2007-11-18 08:14:18

function LineAngle(Point1, Point2: TPoint): Extended;
var
X, Y: Extended;
begin
X := Point2.X - Point1.X;
Y := Point2.Y - Point1.Y;
Result := Degrees(ArcTan2(X, Y));
end;

n3ss3s

2007-11-18 08:15:13

O.o

Seriously?

EDIT: ArcTan2 is divine…

EDIT EDIT: Forgot to thank you, thanks !

Wizzup?

2007-11-18 09:14:46

Although the ArcTan returned in Kevin's example might not be the angle you're looking for. For example:

Function GetCompassAngle: Extended;

Var
Compass: TPointArray;
Point: TPoint;

Begin
FindColorsTolerance(Compass, 1911089, 540, 2, 590, 40, 0);
If Length(Compass) < 1 Then
Exit;
Point := MiddleTPA(Compass);
Result := Degrees(ArcTan2(Point.Y - 20, Point.X - 561)) + 90;
If (Result < 0) Then
Result := Result + 360;
End;

Note the + 90;
And If Result < 0 Then
…

This returns the degrees like you would like them to appear when getting the compass angle.

But purely math, Kevin's right. It just depends what you will use it for.

n3ss3s

2007-11-18 10:05:04

But I use for things where I need 0-360 so +90/ +360 it is?

Shame there isn't any of these interesting stuff on my grade :(

R0b0t1

2007-11-18 13:57:47



function GetAngle(x1, y1, x2, y2: Integer): Extended;
begin
Result:= (x2 - x1) / (y2 - y1);
end;


Not it?

n3ss3s

2007-11-18 14:13:40

But thats just the Tan or is it arc?

R0b0t1

2007-11-18 14:27:57

Dunno :p.

Wizzup?

2007-11-18 14:35:43

Thats just the slope. :)
You need to preform an arctan on the slope.

n3ss3s

2007-11-18 14:52:41

And Tan = Slope!

Yes, I was right! Yay!

EDIT: Wizzy can you make a Tut of useful trigs?

SKy Scripter

2007-11-19 13:42:35

No… The Slope is


function Slope(x1, y1, x2, y2: extended): Extended;
begin
Result:= (y2 - y1) / (x2 - x1);
end;

Remember Rise / Run Also Y / X

Wizzup?

2007-11-19 14:03:36

SKy.

Tan = Sin / Cos.

AKA

Slope = y / x

SKy Scripter

2007-11-19 15:24:23

From: Wizzup?
SKy.

Tan = Sin / Cos.

AKA

Slope = y / x


Uhmm Thanks for reminding me…? :p

SKy Scripter

2007-11-19 15:25:34

From: Wizzup?
SKy.

Tan = Sin / Cos.

AKA

Slope = y / x


Uhmm Thanks for reminding me…? :p

Sense i knew that XD, but thanks…