SA-MP Forums Archive
trigonometry in programming - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: trigonometry in programming (/showthread.php?tid=447803)



trigonometry in programming - thefatshizms - 01.07.2013

Hello, I've been learning trigonometry lately in my free time and noticed that its often used in programming (as well as in sa-mp). I was wondering, what can trigonometry be used for? and could you give me some examples of code to get my head through the concept.


Re: trigonometry in programming - Pottus - 01.07.2013

Probably the most famous and one of the most simplistic would be getting a position in front of the player https://sampforum.blast.hk/showthread.php?tid=325872 but you could also use it to say calculate the rx, ry of a slope using map andreas. You could calculate animation frames for throwing an object (sine) the uses are endless.


Re: trigonometry in programming - MP2 - 01.07.2013

http://forum.sa-mp.com/showpost.php?...4&postcount=95


Re: trigonometry in programming - jamesbond007 - 01.07.2013

Get direction of Turrent gun to face and shoot player
do stuff with NPC (facing, running, etc..


Re: trigonometry in programming - thefatshizms - 01.07.2013

Sorry if this is a stupid question.. (Haven't been doing trig for long + only in my spare time (my maths teacher isn't teaching me it yet :c ) )

In the function "Floatsin" it takes an angle.. I thought in order to get the sin of something you need to know the size of the hypotenuse and the size of the opposite side.


Re: trigonometry in programming - MP2 - 01.07.2013

I think that's sin-1. sin(angle) sin-1 (asin or arcsin or something) of the opp/hyp.


Re: trigonometry in programming - jamesbond007 - 01.07.2013

Quote:
Originally Posted by thefatshizms
Посмотреть сообщение
Sorry if this is a stupid question.. (Haven't been doing trig for long + only in my spare time (my maths teacher isn't teaching me it yet :c ) )

In the function "Floatsin" it takes an angle.. I thought in order to get the sin of something you need to know the size of the hypotenuse and the size of the opposite side.
new Float:angle = asin(opp/hyp);


Re: trigonometry in programming - thefatshizms - 01.07.2013

Okay thanks, I thini I pretty much get it now. The only thing I don't really get is how Floatsin works.


Re: trigonometry in programming - MP2 - 01.07.2013

What do you mean 'how it works'?


Re: trigonometry in programming - Antonio144 - 02.07.2013

Sine is approximated by using Taylor series