#### Archived

This topic is now archived and is closed to further replies.

# What if there were no trig functions?

## Recommended Posts

What would we do? What is the formula sense of cosine? Or sine for that matter? I must''ve missed a chapter because after so many years of using it and taking them for granted, I still don''t know how a calculator (or c++) for that matter calculates this stuff? Do they have a really slow look up tables built within? Is it yet another calculus trick? If anyone knows anything about the history of these functions... feel free to post. In the meanwhile, I will be doing some heavy research of my own. -Lewis [m80] Play QUADz MX @ www.m80produxions.com

##### Share on other sites
Hmm, let's see.

Take an X, Y coordinate system.

Pick a random (X,Y).

Get the length of (X,Y) from the origin. (Gotta use square root for that!)

Change (X,Y) to (X / length, Y / length). Call these values (X1, Y1)

Is it now true that X1^2 + Y1^2 = 1?
And sin(a)^2 + cos(a)^2 = 1 always, doesn't it?

So X1 and Y1 COULD represent sine and cosine values.

They correspond to the x,y values lying on a circle of radius 1.

So, the final question is... where does the a in sin(a) and cos(a) come from? Without these trigonometric functions, is the a even useful? I'll leave that up to the person who wants to use this system without the benefit of sin and cos.

That addresses the TITLE of your post, now for the question in its content:

I do believe processors use an approximation algorithm, but I am not aware of the formulas for sine and cosine.

I think I can spit out the formula for sqrt though. Gimme a sec... it involves getting a value from the equation and plugging it back in, getting another value, and doing it over and over until you get a result with little variance from the previous one...

Blah - can't get it. It's been too long. I used it to get an old 1 MHz machine to generate a fast square root using assembly that was good enough for approximating 3D graphics.

Sorry!

Anyway, I do believe processors use a repeating iterative process, but I wouldn't be surprised if the later generation ones use a table lookup of sorts to assist in speeding it up.

[edited by - Waverider on December 27, 2002 3:08:46 PM]

##### Share on other sites
look up tailor series. by far not the only ones (and on calculators by nearly 100% not used, but still, a good start)

for square root, you can take a simpler approach..

think of an area:

A = x*y;

now, if its square, A = x*x, so x=y, right?

well.. just take some starting x (say A/2 is a good guess..), then you can calculate y from it..

y = A/x;

then, y should be equal to x. if _not, take the average of both, and use that as x.. meaning

x = (x+y)/2
and then calc y again.. till y == x

  sqrt(A):  x,y = A/2,A/2;  do:    x = (x+y)/2;    y = A/x;  while y!=x  return x;

of course, don''t test for equality, due rounding errors of float variables, but you get the idea...

just google around, you''ll find tons of different ways to calculate that stuff, really funny ideas from people around.. those here shown by me are old ones, wellknown. still, they work, and are quite simple to remember:D

"take a look around" - limp bizkit

##### Share on other sites
This may be a little backwards but given a right handed triangle the sin of the angle equals the length of the adjacent over the opposite. cos is length of the opposite over adjacent.

other trig functions are basically a mix of the rest of possible combinations.

Its all listed in mathemtaics for 3d games programming if you have that.

##### Share on other sites
If you want to get a bit more complicated you can define sin and cos in terms of the exponential function e^x and complex numbers. I think its something like cosh x = cos ix gives that

(e^iz + e^-iz)
--------------
2

You can similarily show sin x is the same but with a minus sign in there instead of plus.

##### Share on other sites
They use what is called a taylor series or actually part of a taylor series. Basically it is a polynomial that approximates a sine function. A polynomial is a function of the form f(x)=a0*x^0+a1*x^1+a2*x^2+...an*x^n where n is a natural number. The actual taylor series is a polynomial of infinite degree. So to get the exact value of sin(45 degrees) takes evaluating an infinite number of terms. You are within +/- some error of the correct answer within a limited number of terms though. A floating point number cannot exactly represent 1/3, but it can do so close enough for most purposes. Same with 1/sqrt(2). So you just evaluate enough terms that any more wouldn''t result in you returning a differant answer. Here is a link that gives an infinite sum for sine. If you are unfamilar with summation notation you can find explainations of that on there. Then if you evaluate it as 1 to 2,3,4... instead of infinity you will see that it keeps getting closer and closer to the right answer.

##### Share on other sites
What, you can''t count to infinite? For shame

##### Share on other sites

some mean stuff right there!

-Lewis [m80]
www.m80produxions.com

[edited by - LewieM80 on December 27, 2002 6:25:32 PM]

##### Share on other sites
Thanx fellaz... I think i''m going to go and polish up on my calculus! That complete idiot''s guide is great, by the way!

I probably won''t sleep for the next 4 days. Thanks a lot!

-Lewis [m80]
www.m80produxions.com

• ### Forum Statistics

• Total Topics
628333
• Total Posts
2982139

• 9
• 24
• 9
• 9
• 13