• Create Account

## Angle between two vectors - the law of cosines - derivation problem

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1FlyingDutchman  Members

207
Like
0Likes
Like

Posted 11 February 2012 - 03:23 AM

Hello math community,

i am studying for math at the moment and I am stuck a bit with the derivation of the law of cosines. First of all, sorry if i mention some things wrong, I study in german so it could be that we name some things different. :-)

My problem is that i don't know how to go on after a certain step. It would be cool if you could point me in the right direction .

Problem:

Derive the law of cosines from a triangle made of 2 vectors

a = { ax, ay az }
b = { bx, by, bz }

c = b - a

All lengths are unknown and arbitrary.

So, we are looking for c, alpha, beta & gamma

alpha is between c and b
beta is between c and a
gamma is between a and b

the longest side is c which can be separated into p and q which will give me two right angled triangles.

From this information i can easily get

cos alpha = p / b -> p = b * cos alpha

cos beta = q / a -> q = a * cos beta

c = p + q

c = b * cos alpha + a * cos beta

so far so good ^-^

In the book is written that I shall do the same for the sides a and b. And that is were i get stuck. All the time i am calculating the same stuff on and on again but i am not able to go one step further. It seems that i am missing some variable or s.th.

Lets say the opposite leg of alpha is h

so b = sqrt ( p * p + h * h )

p = cos alpha * b

h = ??? <- how

i ??

The goal is to get

c*c = a*a + b*b - 2ab*cos gamma

I open sourced my C++/iOS OpenGL 2D RPG engine :-)

See my blog: (Tutorials and GameDev)

http://howtomakeitin....wordpress.com/

### #2Ripiz  Members

538
Like
1Likes
Like

Posted 11 February 2012 - 07:28 AM

I'm not sure if this is correct, so please double-check:
b = sqrt(p*p + h*h)
b^2 = p^2 + h^2
b^2 - p^2 = h^2
h = sqrt(b^2 - p^2)
h = sqrt(b^2 - (cos(alpha) * b)^2)
h = b * sqrt(1 - (cos(alpha))^2)
h = b * sqrt((sin(alpha))^2)
h = b * sin(alpha)

### #3jjd  Members

2140
Like
1Likes
Like

Posted 11 February 2012 - 07:41 AM

Since you are working with vectors perhaps you should take a look at using the dot product, i.e. a.b = |a||b| cos(theta)

--www.physicaluncertainty.com
--irc.freenode.net#gdnet

### #4FlyingDutchman  Members

207
Like
0Likes
Like

Posted 11 February 2012 - 10:37 AM

Hey , thanks for both answers..

I had as well the solution with h = b * sin alpha but the challenge is to do it without the sin :-)

Also no dot products ...:-(

I open sourced my C++/iOS OpenGL 2D RPG engine :-)

See my blog: (Tutorials and GameDev)

http://howtomakeitin....wordpress.com/

### #5Ripiz  Members

538
Like
1Likes
Like

Posted 11 February 2012 - 02:24 PM

Law of cosines states so I cannot see what's wrong with using

Anyways, your c = b * cos alpha + a * cos beta looks like Trigonometry proof from Wikipedia (source: http://en.wikipedia.org/wiki/Law_of_cosines#Using_trigonometry).

### #6FlyingDutchman  Members

207
Like
0Likes
Like

Posted 12 February 2012 - 07:38 AM

sin^2 A + cos^2 A = 1

did it

THANKS! :-)

btw.. how are writing these fancy formulas??

I open sourced my C++/iOS OpenGL 2D RPG engine :-)

See my blog: (Tutorials and GameDev)

http://howtomakeitin....wordpress.com/

### #7Ripiz  Members

538
Like
0Likes
Like

Posted 12 February 2012 - 01:34 PM

### #8FlyingDutchman  Members

207
Like
0Likes
Like

Posted 13 February 2012 - 05:01 AM

:-) yeah but sometimes its hard to filter out the right information.. i was a bit stuck in my head .. now its pretty easy of course.. i was confused because of the book..

thanks a lot though

I open sourced my C++/iOS OpenGL 2D RPG engine :-)

See my blog: (Tutorials and GameDev)

http://howtomakeitin....wordpress.com/

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.