BIT-101 [2003-2017]

Trig is cool


As many of you know from frequenting my site, source code, tutorials, and books, I use a lot of trigonometry to create various effects. At least I used to to think I used a lot. All I really ever used was sine, cosine, arctangent, and occasionally the law of cosines.

Usually, whenever I write about math or physics, I’m overly careful to point out that I haven’t done any formal study of the stuff. Well, all that’s starting to change. Last fall I did a College Algebra course and right now I’m wrapping up Precalculus. The last couple chapters have been heavy into trig. There’s more trig than I ever considered existed.

The last chapter covered all kinds of trig functions and inverse functions including all those trigonometric identities. Stuff makes my head spin. I think I’m supposed to memorize all those for the final, which kind of scares the crap out of me.

This chapter we’re covering the laws of sines and cosines, and now moving into vectors, dot product, cross product. This is the big payoff for me. I’ve dabbled in the stuff before, but mostly just copying down formulas and plugging in variables. Now I’m starting to understand it. You can do some really cool stuff with that. Just started playing with some of it last night and came up with this:

https://www.bit-101.com/misc/trig/angles.html

The free end of the arm is draggable. You can envision some cool mechanical devices that could be made with this. 

Then I got thinking of a problem I had tried to solve for ages. Basically, you have a ball bouncing around the stage. It goes past one of the boundaries. To make it bounce, you reverse its velocity on the axis of the collison – x or y. But you also have to move the ball so that it’s just touching the wall/floor/ceiling, not extending through it. I’ve always faked it by just adjusting its position on that same axis. But I’ve always known that it wasn’t quite accurate. I know that I should be actually be moving it back along the line of velocity to the point where it is just hitting.

So this morning, I sat down and drew a diagram and suddenly it was all very clear to me. I worked out the various trig formulas that would calculate that exact point. Tested it out. Worked like a charm!

Then I ran two objects side by side, one using the old faked method, one using the new accurate method. Truth is, you can’t really see a difference. If it’s moving really slow, the difference is only a couple of pixels. If it’s moving fast, the difference may be larger, but it’s moving so fast that you can’t see the difference.

So the result is that I’ll probably continue to use the old hack, as it’s more efficient, though less accurate. But it’s great to have worked out the correct method and have that available to pull out if I need it. I’ll probably eventually post it in the lab if anyone wants to see it.

« Previous Post
Next Post »