PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Cotan and fixed point problem

BurnedImageGames · 18 Dec 2007, 19:24 UTC
I'm having problems getting the correct info from ClassEMath::Cotan. I would like to find an angle of a right triangle. Say x0,y0 = 0,0 and x1,y1 = 20,15. tanX = 15/20 = 0.75 the cotan would return the degree 36.87. I could then use this info to set a trajectory from x0,y0 to x1,y1. I understand that the value return by Cotan is fixed point. I have tried converting it but I can not tell if the problem is in my use of the Cotan function or the FixedToFloat function. Also is there a way I can draw the value of a float to the screen?
BurnedImageGames wrote:I'm having problems getting the correct info from ClassEMath::Cotan. I would like to find an angle of a right triangle. Say x0,y0 = 0,0 and x1,y1 = 20,15. tanX = 15/20 = 0.75 the cotan would return the degree 36.87.


Erm, no. cotan(x) is defined as 1/tan(x) so that doesn't get you anywhere. What you probably want is atan() which returns the angle (usually in radians) whose tangent is x, i.e. 15/20.

However, it seems that ClassEMatch doesn't have anything similar :(

If you don't need it very often you can always use

atan x = x - x^3/3 + x^5/5 - x^7/7 ...

or use a precalculated table as atan(x) is only defined for -1 < x <= 1

HTH
Hi BurnedImageGames,

A function to get the angle based on the x/y difference will be added to an upcoming release.