🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Really dumb math problem.

Started by
4 comments, last by NeoPnoy 24 years ago
Ok this is probably easy for you guys but i dont know how to do this. I have 2 lines. I vertical and the other one is dynamic which means it can be pointing at any direction. (x1,y1) C /\ / \ b/ \a / \ / \ (x2,y2) (x3,y3) how do i find the angle betweent them? that angle im trying to find is angle C. how do i do that? btw. both lines start out in the same direction, and if i connect the enpoints, it will make a right triangle. email me at neopnoy@yahoo.com thanks.
..leTs PuT oUr ImAgInAtiOn iN wOrK aNd sHoW iT tHrOuGh pRoGrAmMinG...
Advertisement
Ok, well, since they both begin at the same point and form a right angled triangle, you can use the cosine ratio to find the angle.

simply call your languag''s inverse cosine function on the two lines'' lengths.

-Mezz
I forgot the law of cosines. What is it again? And how do you the inverse or sine or cosine on the comp? What functions?
..leTs PuT oUr ImAgInAtiOn iN wOrK aNd sHoW iT tHrOuGh pRoGrAmMinG...
hi
you can use dot product in order to find cosine :
let be AB the vector for the first line defined by points A(xa,ya) and B(xb,yb) and CD the vector for the second line defined by points C(xc,yc) and D(xd,yd)
so we have :

AB(xb-xa,yb-ya) CD(xd-xc,yd-yc)

AB.CD=/AB/*/CD/*cos(AB,CD)

with /AB/=sqrt((xb-xa)²+(yb-ya)²)
/CD/=sqrt((xd-xc)²+(yd-yc)²)

we have also:
AB.CD==((xb-xa)*(xd-xc))+((yb-ya)*(yd-yc))

so :
cos(AB,CD)=(((xb-xa)*(xd-xc))+((yb-ya)*(yd-yc)))/(sqrt((xb-xa)²+(yb-ya)²)*((xd-xc)²+(yd-yc)²))


in order to find sine, use cross product

AB X CD=/AB/*/CD/*sin(AB,CD)

we have also

AB X CD=a*d-b*c

so :

sin(AC,CD)=(a*d-b*c)/(sqrt((xb-xa)²+(yb-ya)²)*((xd-xc)²+(yd-yc)²))

you have to calculate both sine and cosine because for one value of cosine you have two angles : cos (alpha) = cos (-alpha)

>>And how do you the inverse or sine or cosine on the comp? What functions?
sorry i don''t know!

hope that help

lunasol

By inverse of cosine or sine do you mean finding the angle when you know the value? If so, use acos(), asin(), and atan(). These are arc cosine, arc sine, and arc tangent.

Morgan
Thanks guys!
..leTs PuT oUr ImAgInAtiOn iN wOrK aNd sHoW iT tHrOuGh pRoGrAmMinG...

This topic is closed to new replies.

Advertisement