n3ss3s
01-22-2008, 12:24 PM
Propably the most of you who are reading this, have also tried Zephyr's Tut, but I'm trying to make the things more simple.
Ready? K
Look at this first:
http://cgi1.math.umb.edu/~greeley/PreCalculusReview/PythagoreanTriangle.jpg
The adjacent is the same as "b"
The opposite is the same as "a"
The hypotenuse is the same as "c"
Keep those in your mind.
Then unit circle equation:
x^2 + y^2 = 1
Unit circle's radius is always "one".
That might sound confusing - "one what?!", but just keep that in your mind too, you'll understand later.
Okay, now have you ever seen anything like this:
"X := MidX + Round(R * Cos(Radians(Angle - 90)));"
"Y := MidY + Round(R * Sin(Radians(Angle - 90)));"
lets start breaking it -
MidX is the midpoint of the circle, that on its arc you want to find a point, kay?
Now, remember when I earlier said that unit circle's radius is one?
Good -
Sin & Cos
The sine function returns the distance to unit circle's arc, the Y -axis.
cose function returns the X axis.
Now, here comes the part why do we do the "R * sin/cos..." thing:
Well, now obviously when we are talking about pixels usually here, you don't need a circle with radius of one pixel for anything, do you?
Well, what if we do it this way:
r := The distance you want the point to be from the origin (midx, midy)
r * sin/cos would start making sense, right?
Thats r times the amount of the distance from unit circles origin :)
So, lets say that our sin would return 0.5, that means it goes half of the unit circles radius.
If we want it to be for example 76 pixels away from our origin, 76 is the minimap's radius, now, if we wanted for example want to have a point on the mm arc that is 30 degrees (clockwise from north), we would do:
X := MMCX + Round(76 * Cos(Radians(30 - 90)));
Y := MMCY + Round(76 * Sin(Radians(30 - 90)));
Voíla.
Now you're thinking "What the *BLEEEEEP*!?!ShIFT+1!!1!*, where's my 30 gone, thats -60!".
The answer is, that unit circle is [-180..180] / [-Pi..Pi] and the angle 0 is actually where 90 "should" be.
The trigonometric function's angle parameters have to be given in radians.
Radians := Degrees / 180 * Pi
ArcTan - the legendary function of confusshizzliation.
ArcSin(Sin(x)) = x
ArcCos(Cos(x)) = x
and so on.
The Arc -functions are the inverse functions of the triginometric functions sin, cos, etc.
Okay, to the point you're here to get an angle of something.
Its actually quite simple:
Angle := Round(Degrees(ArcTan2(y1 - y2, x1 - x2))) + 90;
If Angle < 0 Then
Angle := Angle + 360
The + 90 is because without that, if we had the angle that "actually is 90", it'd be 0 :)
:)
I had very good ideas for this tut in school, but now I can't remember, so just ask...
Added something I just learned myself too - the cosine law:
a² = b² * c² - 2 * b * c * cos α
so the length of adjacent is Sqrt(a²) :)*
Ready? K
Look at this first:
http://cgi1.math.umb.edu/~greeley/PreCalculusReview/PythagoreanTriangle.jpg
The adjacent is the same as "b"
The opposite is the same as "a"
The hypotenuse is the same as "c"
Keep those in your mind.
Then unit circle equation:
x^2 + y^2 = 1
Unit circle's radius is always "one".
That might sound confusing - "one what?!", but just keep that in your mind too, you'll understand later.
Okay, now have you ever seen anything like this:
"X := MidX + Round(R * Cos(Radians(Angle - 90)));"
"Y := MidY + Round(R * Sin(Radians(Angle - 90)));"
lets start breaking it -
MidX is the midpoint of the circle, that on its arc you want to find a point, kay?
Now, remember when I earlier said that unit circle's radius is one?
Good -
Sin & Cos
The sine function returns the distance to unit circle's arc, the Y -axis.
cose function returns the X axis.
Now, here comes the part why do we do the "R * sin/cos..." thing:
Well, now obviously when we are talking about pixels usually here, you don't need a circle with radius of one pixel for anything, do you?
Well, what if we do it this way:
r := The distance you want the point to be from the origin (midx, midy)
r * sin/cos would start making sense, right?
Thats r times the amount of the distance from unit circles origin :)
So, lets say that our sin would return 0.5, that means it goes half of the unit circles radius.
If we want it to be for example 76 pixels away from our origin, 76 is the minimap's radius, now, if we wanted for example want to have a point on the mm arc that is 30 degrees (clockwise from north), we would do:
X := MMCX + Round(76 * Cos(Radians(30 - 90)));
Y := MMCY + Round(76 * Sin(Radians(30 - 90)));
Voíla.
Now you're thinking "What the *BLEEEEEP*!?!ShIFT+1!!1!*, where's my 30 gone, thats -60!".
The answer is, that unit circle is [-180..180] / [-Pi..Pi] and the angle 0 is actually where 90 "should" be.
The trigonometric function's angle parameters have to be given in radians.
Radians := Degrees / 180 * Pi
ArcTan - the legendary function of confusshizzliation.
ArcSin(Sin(x)) = x
ArcCos(Cos(x)) = x
and so on.
The Arc -functions are the inverse functions of the triginometric functions sin, cos, etc.
Okay, to the point you're here to get an angle of something.
Its actually quite simple:
Angle := Round(Degrees(ArcTan2(y1 - y2, x1 - x2))) + 90;
If Angle < 0 Then
Angle := Angle + 360
The + 90 is because without that, if we had the angle that "actually is 90", it'd be 0 :)
:)
I had very good ideas for this tut in school, but now I can't remember, so just ask...
Added something I just learned myself too - the cosine law:
a² = b² * c² - 2 * b * c * cos α
so the length of adjacent is Sqrt(a²) :)*