Click here to Skip to main content
15,921,467 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am trying to find the X and Y coordinates of a certain point in my game.

I have a starting point ("origo"), I have the length of my object (in pixels), and I have the rotation of the object.

In other words: if the object would be lying on the ground the X point would be origo + the length of the object, and the Y point would be the same as origo.

But what if the object is tilted say 55 degrees? I'm trying to locate the nearest X and Y position of where this object points then.

The reason why I ask is that I am creating a game with a cannon and shots that should be fired at this position, not from the middle of the object.


Thanks for any suggestions!

Petter

What I have tried:

I have looked at the sinus, cosinus, and tangent math formulas, but don't think they are applicable, and in any case I don't know how to write this in C#.
Posted
Updated 7-Aug-16 1:02am
v3

1 solution

I came up with the solution myself. When I drew the line, angle, and the coordiante system I saw that opposite the length of the object, the corresponding angle is always 90 degrees.

Thus, I have a 90 degree angle, a known angle, and one of the two lines' length.
This means that I can use the law of sines.

I hope this helps anyone in the same situation.

Petter
 
Share this answer
 
Comments
Patrice T 7-Aug-16 9:03am    
nice to see you found the answer.
Use Accept answer to close the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900