Advertisement

Trigonometry Problem

Started by May 17, 2002 09:14 AM
1 comment, last by MaSo 22 years, 9 months ago
First thanks for taking the time to read this! I''ll try to explain my problem as well as I can. I have an main object that is 64x64pixels drawn on the screen and I want to place another graphic in relation to it. It is my hope to draw this 13 pixels below and 9 pixels to the left of the main object. Simple enough so far except the object can rotate throughout 360 degrees and I cannot get the second object to stay in the correct position. I know i definetly need to add 32 to the X, Y to get the centre of the main object then minus 13 off Y and 9 off X to get the correct position when it is horizontal. I assume I need to use sin and cos somehow to calculate the ships angle (which is stored in radians) and introduce it into the equation? Have been trying to a couple of days and not made much progress so any help would be greatly appreciated. MaSo
I'm sorry I'm too tired to write down a coherent description of the answer to your problem right now. Fortunately, hundreds of people have already done it.

Just use the usual techniques to find tutorials/essays/descriptions of a "rotation around a point in two dimensions".

PS: You are on the right track, the sin of the angle can represent the scale of the x component and the cos of the angle can represent the y component. Then scale those comnponents by the length of the vector and you have your offset.

[edited by - novalis on May 17, 2002 10:26:12 AM]
If a man is talking in the forest, and there is no woman there to hear him, is he still wrong?
Advertisement
Ok I'm gonna explain this for you. Here's how you do that, Instead of your 13 x 9. Pick a distance in pixels that you want the second object away from the first. Let's say 10 pixels. Ok here goes.

Object2X = Object1X + cos(Angle in Radians) * 10 <---10 is the distance from the first object
Object2Y = Object1Y + sin(Angle in Radians) * 10 <---Same goes for this 10

Ok that should do it. But to explain some things more into detail. Angle in Radians is basiclly that. It's the angle that you second object is away from your first. To convert degrees to radians you use this formula.

Radians = Degrees * (PI / 180)

Ok now the 10 that I added into the formula above can be any distance that you want your second object away from your first.

That's all you need, isn't math fun. Tell me if this helps you! E-mail me for more help with math. Dildan2004@hotmail.com

Horny Farmer (Jolly Rancher)

[edited by - VisualB4BigD on May 20, 2002 5:25:19 AM]

This topic is closed to new replies.

Advertisement