# How can i figure out the coordinates of a projectile after it has moved at an angle

This topic is 813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Imagine I was making a pong game. If the ball starts at (0,5), the goal is a line 10 units away starting from (10,0) and ending at (10,10) and the ball moves towards the line at an angle, say 20 degrees. How can I find out where on the goal it will land?

I appreciate any answers and suggestions.

Edited by szokoz

##### Share on other sites
Treat the path the ball will travel as a ray, treat the goal as a line segment, and perform a ray-line segment intersection.

If the ball is a circle with a nonzero radius, you'll have to do ray-capsule intersection instead. Edited by Nypyren

##### Share on other sites

This gets easier with vector math, instead of an angle, you have a directional vector that you use for the ray.  If you have walls, you'll also need to reflect the ray and compute that intersection (and if that ray intersects a wall, you compute that intersection... you'll want to limit the check by distance, or you'll look where the ball is an infinite number of bounces later)

##### Share on other sites

Some examples of those methods in use? It would help me understand how I implement the direction/angle into those methods since I'm a bit confused on how that works.

##### Share on other sites

So your ball has a position (x,y) and a direction vector (dx, dy).

If you want to specify the direction in terms of an angle then you need to calculate the (dx,dy) vector using the parametric equation of a circle:

dx = cos(angle)

dy = sin(angle)

Using (x,y) and (dx,dy) you have a ray. So now you can use ray-line intersection to find out the point of intersection with your 'goal'.

This is the point where the 'center' of your ball would intersect the goal.

If necessary you could apply a bit more trig to work out where the perimeter of the ball 'first' intersects the goal.

##### Share on other sites
https://en.wikipedia.org/wiki/Polar_coordinate_system#Converting_between_polar_and_Cartesian_coordinates
https://en.wikipedia.org/wiki/Euclidean_vector

A vector is (x,y) in 2D and (x,y,z) in 3D. Sometimes there's a w component but you can ignore that here.

A ray is two vectors: One indicates a staring position, the other indicates the direction of travel.

A line segment is two vectors, but instead of a starting position and a direction, it's a starting and ending position.

Ray-with-other-object collisions usually solve for "t" which is a number indicating how far along the ray the collision occurs, usually in the form: collisionPoint = rayStartPoint + rayDirection * t

A capsule is a box with circles at each end (in 2D) or a cylinder with spheres at each end (in 3D), or in another way of thinking about it, the surface of all points that are a constant distance away from a line segment inside the capsule. The idea here is that instead of trying to collide your ball with a line, you simultaneously shrink the ball to a point and expand the object-to-collide-with by that radius in all directions, and in certain cases this makes the collision equations simpler to solve. When you expand a line segment by a constant radius in all directions, you get a capsule.

The reason why you could use a capsule in a pong game is that the ball might hit one of the ends of the paddle. If you use a plain two-line-segments test, you will get a collision point that isn't quite where the ball will actually collide. The difference will be more extreme the further from perpendicular the ball is moving with respect to the paddle's surface. Edited by Nypyren

##### Share on other sites

I hope it's not too late to thank you all for you help. Most Appreciated!

1. 1
2. 2
Rutin
29
3. 3
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633648
• Total Posts
3013111
×