Finding the Angle

Moonglum

New member
Joined
Apr 20, 2023
Messages
2
Please can someone give me a method to calculate the angle in the following diagram. Much appreciated.

1682022614620.png

Moon.
 
Please can someone give me a method to calculate the angle in the following diagram. Much appreciated.

View attachment 35623

Moon.
They don't say what "[Xa,Ya]" means. (Square brackets are for matrices, not points. There is no definition provided for "a". Is "a" meant to be a multiplier, or is it a subscript?)

Also, no information is given about the "Angle?". (Why is it being measured from the y-axis rather than from the x-axis? Etc, etc.)

With no definitions and no information, there is no way to proceed. Kindly please consult with your instructor regarding the missing information. Thank you!

Eliz.
 
With no other information I have two answers.
1) Use a protractor.
2) Tan (reference angle) = abs(y0/x0). Then the reference angle equals tan-1(abs(y0/x0)).
What is that angle in quadrant 3 equal to??
 
Please can someone give me a method to calculate the angle in the following diagram. Much appreciated.

View attachment 35623

Moon.
If the context involves computer programming, do you have the atan2 function available? If so, how is it defined? (There are different versions.)

We really need to know more about what you are doing, and why.
 
Many thanks for coming back to me.

Context:
-----------
I am learning the computer programming language C++ and using a system called SFML to do the graphics. I am trying to write an improved version of the old Atari game Asteroids. I use x,y coordinates to create the ship and the rocks. I use Sine and Cosine to calculate vector points from an origin. so, for example: The ship has origin coordinates ox,oy. The radius of the ship is 20 pixels. The front point of the ship is calculated with the following.

nx = ox + sin(Angle) * 20;
ny = oy + cos(Angle) * 20;

Where nx and ny are the x,y coordinates of that point, ox and oy are the x,y coordinates of the centre of the ship, and Angle is the amount of rotation of the ship. With this system, I can then spin the ship around the central point. Sin and cos are the C++ functions for Sine and Cosine respectively. The asin, acos, tan and atan functions are also available. Using this technique, I can draw wire frame representations of the rocks and the ship. The gray frame shown here is simply for reference and is not drawn in the game.

Dart Ship.png

Calculation:
---------------
With any computer game, there is a cost to calculation. Sine, Cosine and Tangent functions are particularly costly due to the number of calculations required to generate answers. I have largely mitigated this cost by calculating 360 values of Sine and Cosine (for degrees in a circle) and storing them in a table which is then referenced in the main game. Other computer functions will also take up time and so I am keen to reduce the number of lines of code to a minimum to keep the game speed.

Rocks:
--------
Each rock has a slightly different shape and this is calculated using random modifiers to a set structure. The rock is a seven sided shape. Each corner of the rock is calculated based on a radius defined for that corner which I have labelled rs[0] through rs[6] respectively. The structure may seem a little complex but the advantage is that the rocks can be spun. The effect is a great chunk of rock slowly spinning through space.

Rock Structure.png

Question:
-------------
Missiles fired from the ship can impact a rock from any side. I need to calculate the angle for the point of impact so that the rock may be split at that point. I have some very clumsy code that sort of does this but thought there must be a better way. To simplify my calculations, I have set the rock origin to 0,0. Xa and Ya (from the first diagram) are the coordinates for the point of impact of the missile. My question is, how do I calculate how far round the rock the missile is, ie: the angle of impact.

Game Sequence.png

Please let me know if you have any more questions. I am happy to share with you my code if that would help. Much appreciated.

Moon.
 
Top