PDA

View Full Version : Trigonometry 303



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²) :)*

ZephyrsFury
01-22-2008, 01:10 PM
Very good considering you're 12 and haven't learnt this stuff yet (well I don't think you have). Just one question thats bothering me... where did you get the 303 from? :)

n3ss3s
01-22-2008, 01:22 PM
where did you get the 303 from?

Umm... Nothing.. I mean nowhere :p from 101 ofcourse x)

Ofcourse I have learned this, how would've I been able to write / code this else?

My grandfather and SRL are teaching me :)

Negaal
01-22-2008, 01:46 PM
OmgOmgOmgOmgOmgOmg, I really needed this since I can't understand nothing from Robot's guide and as I said I don't know what are sin-cos-tan:)


Thank you

n3ss3s
01-22-2008, 01:49 PM
Glad you liked it :)

Btw, what does
Shit hits the van! mean? :p

Negaal
01-22-2008, 02:16 PM
Glad you liked it :)

Btw, what does mean? :p

It's just expression:D
I just like it...

Edit: I'v read it once so far...Nothing...I'll try maximum 20 times more until I give up...

Edit: This part is clear for me:) Because we learned it in school today ^^
Radians := Degrees / 180 * Pi
Degrees := Radians * Pi /180
:D

Edit: I still don't know what are sin cos tan cot etc...
Explain them too, that may solve problem, I'm getting logical things pretty fast if I know what is what...

Edit:
Whats wrong with it: :confused:
program New;
var x : integer;
begin
x := 10;
x:=ArcSin(Sin(x));
writeln(inttostr(x));
end.

Edit:
program New;
var x : extended;
begin
x := 10;
x:=ArcSin(Sin(x));
writeln(floattostr(x));
end.


-0,57522203923062

Lol?

Edit: Is there any way drawing it's arc on canvas...
Or something like Yakman's RadialWalk aid?

n3ss3s
01-22-2008, 02:28 PM
Maybe you should tell what cannot you understand?

Negaal
01-22-2008, 03:07 PM
Maybe you should tell what cannot you understand?

Ok,
1) What are Sin, Cos, Tan, Cot
2) Where should mid point began and where should x and y be
3) How is "Angle" used, what angle is it?

This is only beginning, but If I could understand them, maybe I could understand others aswell..

Edit:
Also this is very confusing, I tried different angles...thats why asked about midx and midx, and x , y
program New;
var x,y,midx,midy, angle : extended;
begin
midx:= 200;
midy := 200;
angle := 360;
X := MidX + Round(10 * Cos(Radians(Angle - 90)));
Y := MidY + Round(10 * Sin(Radians(Angle - 90)));
writeln(floattostr(x)+', '+floattostr(y))

end.


Successfully compiled
208, 194
Successfully executed
Successfully compiled
210, 200
Successfully executed
Successfully compiled
200, 210
Successfully executed
Successfully compiled
200, 190
Successfully executed

n3ss3s
01-22-2008, 03:11 PM
You think it too complicated, you need to reserve only 3 bytes excluding spaces from your brains for these -

Sin: b/c
Cos: a/c
Tan: b/a
Cot: a/b

2. Anywhere

3. Angle was an integer example - you want [AngleHere] in there? :p

ZephyrsFury
01-22-2008, 03:15 PM
Sin, Cos and Tan are trigonometric ratios. If you look at the diagram in the tut. Sin is Opposite/Hypotenuse. Cos is Adjacent/Hypotenuse. Tan is Opposite/Adjacent. These ratios are useful for finding distances and angles within a triangle. Cot is another ratio but is more advanced (can't remember what it is).

Try not to get confused with this stuff if you haven't learnt it yet. It will be hard when you do learn it if you get confused.

n3ss3s
01-22-2008, 03:25 PM
Zephyr -

Sin & Cos
Tan & Cot

"Sine, Cosine"
"Tangent, Cotangent" , remember? :)

nielsie95
01-22-2008, 05:22 PM
Edit:
Whats wrong with it: :confused:
program New;
var x : integer;
begin
x := 10;
x:=ArcSin(Sin(x));
writeln(inttostr(x));
end.
Lol?


10 is not a valid radian. Convert it using the Radians(Degrees: Extended) function. Then, if you want it Degrees again, convert back with Degrees(Radians: Extended):


program New;
var x : Extended;
begin
x := 10;
x:=Degrees(ArcSin(Sin(Radians(x))));
writeln(FloatToStr(x));
end.

n3ss3s
01-22-2008, 05:26 PM
Or read my tutorial and use Deg / 180 * Pi for the sake of experience :)

Main
01-22-2008, 08:05 PM
Very good considering you're 12 and haven't learnt this stuff yet (well I don't think you have). Just one question thats bothering me... where did you get the 303 from? :)

n3ss3s is 12??:confused:...............

osmm
01-22-2008, 09:42 PM
HAHA funny, I'm 14 and going through my first touch of Trig tomorrow in Geo class. Then I guess when I'm older I got a full class on it =/.

R0b0t1
01-23-2008, 12:33 AM
Now, it is certainly interesting how much we can learn on the internet, right, children?

ZephyrsFury
01-23-2008, 02:56 AM
Zephyr -

Sin & Cos
Tan & Cot

"Sine, Cosine"
"Tangent, Cotangent" , remember? :)

Cotangent is the inverse of tangent (Cot = 1/Tan). I don't use it much but its rather common when dealing with Trig identities and stuff so mathematicians decided to give 1/tan its own name. Same thing with Cosec (1/Sin) and Sec (1/cos).

Main
01-23-2008, 04:48 AM
childrens of nowdays are getting smarter and smarter:D hope one day we'll see kids of all age macroing rs:sasmokin:

Negaal
01-23-2008, 07:52 AM
lol,at 1st i thought this was seriosuly talking about math. But nice tutorial,i like it

It is serious math, if you have reached to 8th or 9th class you'll learn it

n3ss3s
01-23-2008, 11:38 AM
@Zeph: Crap, my bad.

IEatJ00erBaybees
01-25-2008, 02:57 AM
Geometry --> Algebra II --> Pre-Calc --> AP Calc

I own.

n3ss3s
02-17-2008, 02:02 PM
Added cosine law!

Could someone confirm that does the same work for sine if the values are being switched around, like b² = a² * c² - 2 * a * c * sin α ?

richk1693
02-17-2008, 03:43 PM
May l ask where you would ever use this in scripting? Knowledge is always good, but I can't see to think of a situation where you would need this.

n3ss3s
02-17-2008, 03:45 PM
Need the cosine law or what?

richk1693
02-17-2008, 03:53 PM
This whole tutorial in general. It seemed more like a math lesson. (I'm probably just retarded so don't feel bad) May l have an example where you would use this?

mixster
02-17-2008, 04:13 PM
So this is where negaal got the circle code from lol. Ahwell, I'll change the credits in my arc drawer to n3ss3s. Anyway, on the topic - nice, although I learnt trigonemtry before scar, so the whole converting between radians and degress etc. through me off, but I'm back on track now. Also, might be an idea to include a picture of how triangles are used to find the point on the circle (so just a circle with a triangle in it starting from the middle) as that really does make it much clearer.
Richk1693 - One option is when making scar-games. You can use this to create perfect circles when designing the canvas that the game is played on (check Negaal's radar game in 'Other scripts'). You can also use this to replicate a minimap onto an external canvas - thus allowing you to more easily make a D/DTM. It's not obviously useful, but when you need it, it's good to know.

n3ss3s
02-17-2008, 04:48 PM
This whole tutorial in general. It seemed more like a math lesson. (I'm probably just retarded so don't feel bad) May l have an example where you would use this?

Hehe, and you don't feel bad for being retarder ;) Jk/Jk


But seriously, you can't understand what's it got to do with SCAR?

Go look @ MapWalk.scar for example.

RadialWalkEx uses FilterPointsPie, which uses ArcTan.

Maybe you missed it - we use sine and cosine to get the coordinates of a point on an arc, and ArcTan / ArcTan2 to get the angle of something.

So, today's RadialWalking is based on ArcTan and TPA, the old one based on sine and cosine going through mm until radius <= 1 inside the given degrees.

Simply, your life is based on math :)

If you just want to do what you need to, like use FindObj to find an obj or so, you don't necassarily come accross the "roots". No, I am not saying that you were a simpleton or anything...

JuKKa
03-12-2008, 03:33 PM
voi vitun pelle oot 12 ja osaat 9-10 luokan matikka, vähän rajaa hei :D

in english: im just flaming ness...

n3ss3s
03-17-2008, 12:27 PM
In fact... 13 :) But my grandfather is a maths professor so I get a little support from up there :rolleyes:

Sir R. M8gic1an
06-09-2008, 06:05 AM
richk, you would use this when you don't know if the minimap is perfect north.

thank you for the tut n3ss3s :), took some time to understand it and even more time to nail it, but i finally got what i wanted from it :)

~RM

Smartzkid
06-11-2008, 02:45 AM
Good, but if I didn't know trig, it'd confuse the heck outta me.