PDA

View Full Version : Coords of a point in a circle...



n3ss3s
11-03-2007, 01:09 PM
This is nothing big, but even more useful.

Having troubles with remembering all the 'Round(Radius * Sine(x)) + MidPointX' Etc?

Heres the answer for your problems:


Function PointOnCircle(MidX, MidY, Radius, Angle: Integer): TPoint;
Begin
Result.x := MidX + Round(Radius * Cos(Radians(Angle - 90)));
Result.y := MidY + Round(Radius * Sin(Radians(Angle - 90)));
End;


MidX, MidY - Coords of the midpoint
Radius - Distance between the midpoint and the point you wanna get
Angle - angle to get the point of.

Also, that does not need SRL, I wanted to find out the 'real' way...

Free to use, though crediting is nice even this isnt anything big..

ZephyrsFury
11-03-2007, 01:54 PM
Isn't there something similar to this inbuilt into scar. All it does is converts Polar coords to cartesian.

EDIT: Actually nevermind. The ones in the SCAR manual don't serve the same purpose.

n3ss3s
11-03-2007, 01:57 PM
I have no idea what Polar and Cartesian are...

ZephyrsFury
11-03-2007, 02:00 PM
They are ways of specifying a point on a plane. Cartesian coords are x and y while polar coords are distance from an origin (radius) and angle.

n3ss3s
11-03-2007, 02:04 PM
ookay... I think I got it.

Metagen
11-04-2007, 11:57 AM
Ooooh that brings back memories of grade 12 geometry and algebra...

Nice thing you have there.. could be useful for taking compass angle and walking a distance in a direction.

Wizzup?
11-04-2007, 12:21 PM
Next step:

Function InDegreeAndDist(x, y, mx, my, sd, ed: Integer; minr, maxr: Extended): Boolean;

Var
xDeg, d: Extended;

Begin
xDeg := Degrees(ArcTan2(y - my, x - mx)) + 90;
If xDeg < 0 Then
xDeg := 90 - (xDeg * -1) + 270;
Result := ( (xDeg >= sd) And (xDeg <= ed) );
If Result Then
Begin
d := Sqrt(Sqr(x - mx) + Sqr(y - my));
Result := ( (d >= minr) And (d <= maxr) );
End;
End;

:p

n3ss3s
11-04-2007, 08:06 PM
Hehe, I know what it does by the name, but can you tell more specifically what it does?

Tan = b/a, rite?

So ArcTan... ArcTan2...

SHARE YOUR WISDOM GOD DAMIT! :p

Btw, I have a same like function, though how it works is simplier, but does the job though:


Function InPizzaSlice(xx, yy, StartR, EndR, MidX, MidY, MaxRadius: Integer): Boolean;
var
Rx, Ry, Dx, Dy, D: Integer;
Begin
Rx := Round( MaxRadius * Sine(StartR)) + MidX;
Ry := Round(- MaxRadius * Cose(StartR)) + MidY;
Dx := Round( MaxRadius * Sine(EndR)) + MidX;
Dy := Round(- MaxRadius * Cose(EndR)) + MidY;
If (XX > Rx) And (XX < Dx) Then
Begin
Result := (Distance(xx, yy, MidX, MidY) <= MaxRadius);
End;
End;


:p

But hey if not post, or make a tut, can you wizzy tell me about those ArcTans etc and where, how can they be used for effectively, like in your function..

R0b0t1
11-04-2007, 08:25 PM
You mean n3ss3s is getting smarter? :eek:

n3ss3s
11-04-2007, 08:55 PM
You mean n3ss3s is getting smarter?

Nobody said Im not interested in maths?

And I've knew the version of the function with SRL's Sine and Cose a long time though.... (RRW ;) )

And we talk about these things with my grandpa about every time we meet (today once again), and he is a theoretic physic so I can ask him about these things, and then I get an explanation that is more than enough, but even better :p

King of Knives
11-04-2007, 09:52 PM
Next step:

Function InDegreeAndDist(x, y, mx, my, sd, ed: Integer; minr, maxr: Extended): Boolean;

Var
xDeg, d: Extended;

Begin
xDeg := Degrees(ArcTan2(y - my, x - mx)) + 90;
If xDeg < 0 Then
xDeg := 90 - (xDeg * -1) + 270;
Result := ( (xDeg >= sd) And (xDeg <= ed) );
If Result Then
Begin
d := Sqrt(Sqr(x - mx) + Sqr(y - my));
Result := ( (d >= minr) And (d <= maxr) );
End;
End;

:p
Argh, you beat me to it :P

As if! I don't get ANYTHING of that. ArcTan? Arctic Suntan? I just don't...

-Knives

n3ss3s
11-05-2007, 01:21 PM
Now I get it.... It wasnt spam... Wizzy wanted to show off his ArcTan2! :p

Wizzup?
11-05-2007, 04:42 PM
Heh, I just got back from 9 hours of school. Had a math exam of 2,5 hours.

Tan = Sin / Cos;
Tan = Slope;
ArcSin(Sin(z)) = z;
ArcCos(Cos(z)) = z;
ArcTan(Tan(z)) = z;

function ArcTan2(Y, X: Extended): Extended;
ArcTan2 calculates ArcTan(Y/X), and returns an angle in the correct quadrant.
IN: |Y| < 2^64, |X| < 2^64, X <> 0
OUT: [-PI..PI] radians

ArcTan(Delta Y, DeltaX) = 'Math' Degrees.
Those degrees are from -180 To 180, that is why I called them 'Math' Degrees.
You need to 'fix' them to make them like our Degrees.

Then, if the degree is bigger than startDegree and lower than endDegree, it lies between those 2 degrees.
Delta X = X1-X2.
Square Root of (DeltaX^2 + DeltaY^2) = Distance.
Use Distance (Sqrt(Sqr(X1-X2) + Sqr(Y1-Y2));
Distance in 3d is:

Sqaure Root of (DeltaX^2 + DeltaY^2 + DeltaZ^2)

Is the distance >= minDistance and distance < maxDistance then
return true.

Naum
11-05-2007, 04:52 PM
Had a math exam of 2,5 hours.

Lol ridiculus amount of time for a test i have sympathy for you.

n3ss3s
11-05-2007, 05:45 PM
ArcSin(Sin(z)) = z;
ArcCos(Cos(z)) = z;
ArcTan(Tan(z)) = z;

But can you tell what they do? Im pretty sure their purpose isnt to return Cost(x) :p

ZephyrsFury
11-06-2007, 12:42 PM
But can you tell what they do? Im pretty sure their purpose isnt to return Cost(x) :p

Sin(x), Cos(x) and Tan(x) give the sine, cosine and tangent of an angle (in radians for the inbuilt scar functions). ArcSin, ArcCos, ArcTan are the inverse of sin, cos, and tan. ie they change the values back into angles. It a bit hard to explain unless you really want to go into the unit circle and into trigonometry. They basically help you find angles and lengths of sides and stuff when you're dealing with triangles.


Lol ridiculus amount of time for a test i have sympathy for you.

I have a 3 hr and 10 min exam for each of my 6 subjects in about 2 weeks time. :(

n3ss3s
11-06-2007, 02:10 PM
Ahh, the inversing means back to angles! Thanks.



I have a 3 hr and 10 min exam for each of my 6 subjects in about 2 weeks time.

Thanks for last tip, was nice to know you..