Drawing circle and calculating sinus function without trigonometry, power, or root
The formula of a circle is quite straightforward (r=sqrt(x^2+y^2)) but it's not trivial how to draw a circle or calculate the trigonometric functions without advanced math. However, an interesting finding from 1972 makes it really easy.Minsky discovered (by a mistake) that the following loop will draw an almost perfect circle on the screen:
loop:
x = x - epsilon * y
y = y + epsilon * x # NOTE: the x is the new x value here
Turns out that epsilon in the equation is practically the rotation angle in radians, so the above loop will gradually rotate the x and y coordinates in a circle.
Calculating sinus
If we can draw this circle, we can easily estimate the sinus values: for the current angle, which is basically the sum of epsilons so far, we have a height (y), which just needs to be normalized to the 0-1 range to get the actual sinus for the angle.
The smaller the steps (epsilon) are, the more accurate the formula will be. However, because it's not a perfect circle, it can never be a very accurate estimation. If epsilon is large, the algorithm will draw a visible ellipsis instead of a circle (slightly tilted left).
Read full article from Drawing circle and calculating sinus function without trigonometry, power, or root
No comments:
Post a Comment