Arctg table!

Started by
18 comments, last by shaolinspin 14 years, 9 months ago
1. Your use of the abbreviation "ArcTg" for "arctangent" is unusual. The standard abbreviation is "atan" or occasionally "arctan;" you will see either this or "tan-1" in math texts.

2. You say you have no math libraries? You can compute your table using the series expansion,



which I have taken from the Wikipedia article. Note that the return value is in radians.

[Edited by - Emergent on August 3, 2009 6:00:36 PM]
Advertisement
What alvaro is saying is that you have tangent and arctangent mixed up. Arctangent takes in the ratio of sides on the triangle, which could be anything, and then returns the angle, which is between 0 and 360. It is regular tangent that takes the angle as input.
Tangent:[0,360]->[-inf,inf]
Arctangent:[-inf,inf]->[-90,90]

So it sounds like you want tangent(x) for x from 0 to 360, right?
Quote:Original post by Maze Master
What alvaro is saying is that you have tangent and arctangent mixed up. Arctangent takes in the ratio of sides on the triangle, which could be anything, and then returns the angle, which is between 0 and 360. It is regular tangent that takes the angle as input.
Tangent:[0,360]->[-inf,inf]
Arctangent:[-inf,inf]->[-90,90]

So it sounds like you want tangent(x) for x from 0 to 360, right?


Actually, I want something to return the angle from the diference between
the point in the circle and the center of the circle. I believe this fromula applies in this case:

Angle= arctangen (PointY-CenterY/PointX-CenterX)

Cheers.
Quote:Original post by asmcoder
@alvaro: I can have only 360 array's entry, and then check for the nearest array value to the value i got from calculating x-x0/y-y0.

You mean you will search for the value in the table? Then you need a table of tangent, not arc-tangent, as we have been saying from the beginning.

Quote:[...]My environement compiler does not have a math library (no cos, sin... functions) and I cannot install other compilers.

Can you use the code I posted above?

I'll be using your code!
Thanks.
You are welcome. By the way, if you want the answer in degrees (which I don't recommend), simply change the line `double alpha=3.141592653589793238462643383279;' to `double alpha=180.0;'.

I've done that using this formula: Degree=Radian*180/Pi
Btw, why don't you recommend getting degree answers?

Thanks a lot.
Quote:Original post by asmcoder
I've done that using this formula: Degree=Radian*180/Pi
Btw, why don't you recommend getting degree answers?

1) It's a more natural choice. Dividing the circle in 360 degrees is a completely arbitrary decision, although it's a familiar one. The length of a circle measured in radii is 2*pi, so it would be natural to measure angles by specifying the length of the arc determined by the angle, measured in radii, and that's what radians are.
2) It makes derivatives simple. The derivative of sin(x) is cos(x) and the derivative of cos(x) is -sin(x), if you measure angles in radians.
3) Libraries (except for OpenGL) and hardware use radians.
4) exp(i*x) = cos(x) + i*sin(x), as long as x is in radians (if this doesn't make sense, I won't try to explain it).

I've been meaning to write a little article advocating the use of the most natural representation in several types of variables. In short, it would say:
* Prefer vectors to angles.
* Prefer radians to degrees (if you have to use angles at all, which you probably don't).
* Start counting from 0.
* Use ranges of the form [x,y), which include the bottom element and don't include the top element.
* Use a 24-hour format for time, instead of am/pm.
* Use fractions, not percentages.

If you follow those simple pieces of advice, your code will have fewer special cases and many formulas will be simpler.
Cheers for the explanations dude!
I'm very interested on your article. Could you please point me a link to it?

Thanks.
Quote:I'm very interested on your article. Could you please point me a link to it?


Quote:I've been meaning to write a little article advocating the use of the most natural representation in several types of variables. In short, it would say


;)

This topic is closed to new replies.

Advertisement