Calculating the third side of a triangle using sin/cos/tan

javaIsLove

New member
Joined
May 24, 2015
Messages
3
hello,

I'm a beginning programmer and I'm trying to make a gravity simulator. For that i have to calculate the velocity vectors for the particles. That part was quite easy to figure out. Now I need to add all those vectors and get the final direction the particle will move to. Problem is that i never paid attention in class because i passed all the tests without any issues. So my question is: if I have 2 sides of the triangle and all of the angles of the corners, how do i calculate the final side with a formula (like a^2 + b^2 = c^2). Only these triangles do not have a 90deg angle.

thanks in advance :)
if you need any more info or an example, i'll be happy to give that.
 
If I have 2 sides of the triangle and all of the angles of the corners, how do i calculate the final side...?
One could use the Law of Sines or the Law of Cosines. The Law of Sines generally "feels" easier to me, personally, but it's entirely up to you. ;)
 
hello,

I'm a beginning programmer and I'm trying to make a gravity simulator. For that i have to calculate the velocity vectors for the particles. That part was quite easy to figure out. Now I need to add all those vectors and get the final direction the particle will move to. Problem is that i never paid attention in class because i passed all the tests without any issues. So my question is: if I have 2 sides of the triangle and all of the angles of the corners, how do i calculate the final side with a formula (like a^2 + b^2 = c^2). Only these triangles do not have a 90deg angle.

thanks in advance :)
if you need any more info or an example, i'll be happy to give that.

As a programmer, something to always keep in mind is the cost of an operation. Even if the application doesn't require it, you should at least think "What costs me more, the sine functions or the cosine function?" Generally the conclusion is "The performance is good enough with either" but, if, for example, you were doing some real-time MMO game, it might well be worth doing the law of cosines since it is a single trig function as compared to two trig functions and a trig function may cost you much more computationally (and possibly more memory) than a few multiplies and a square root.
 
thanks for all the replies :D
i'm going to try this now, will let you know if it works.
 
Ishuda, are you saying that SQRT[a + COS(u)]
takes less time than [aSIN(u) / SIN(v)]?

I was under the impression that the lesser the number of SQRTs,
the faster a loop program will work...

Actually depends on machine, compiler and number type but using a1/2 can be a lot faster than sqrt(a). Again depending on machine and compiler, for the actual computation (as opposed to a table lookup) the advantage of using the (a+cos(u))1/2 over (a*sin(u)/sin(v)) is maybe 1.5 to 1 or better. For example, look at
http://hades.mech.northwestern.edu/..._Mathematical_Operations#Cosine_.28Test_15.29
and don't use pre-comps you get an advantage of about 1.5 to 1 for floats [regular 'decimal' numbers to about 7 place accuracy]. Square root is same as 1/2 power if compiler is optimizer for that. If you do doubles ['decimals' to about 15 places] the ratio raises a little.

Of course that's maybe 41\(\displaystyle \mu s\) as opposed to about 29\(\displaystyle \mu s\) so you need to be running some pretty intensive stuff.
 
this part works :D

now I found that i need to get one of the angles (which i thought i already had, but i didnt). so i found this picture online
lcos.gif

this explains the cosine law some of you suggested, but if i wanted to know angle a? is there a way to calculate this, and if so, how?

thanks very much in advance again :)
 
Top