# Find Coordinates of Exit Point

I'm trying to make a bullet penetration system. Taking a look at the picture below could help explain what I want better.

If we know the coordinates of a square shape as well as AB vector with direction coefficient, how do we find X,Y for C point?

Basically I'm trying to find the X,Y coordinates of the point of the opposite side of an object of another point. As you can see I'm not exactly going for realism as it's linear. Below are a couple more examples to clarify my objective.

===========================================================================

Any help is greatly appreciated :D

• This is a lot easier if, instead of regarding the quad as a list of points, we think of it as the unit square that's been scaled, translated, rotated, and skewed. (eg. We could use one 2x3 matrix instead of 4 2D points). Is such a representation an option for your case? – DMGregory May 4 '18 at 11:32
• I'm not very sure as I've not dealt with linear algebra much. Generally any solution that can be easily calculated in code is acceptable. If you don't mind taking the time to tell me how to calculate it as presented above(using 4 2D points like you said) I'd appreciate it more since linear algebra isn't really my thing but if you could provide a thorough explanation of the other way then I won't mind :) – Black Scarlet May 4 '18 at 11:58

You can intersect the ray against each of the edges (segments).

If you get zero intersections, the ray misses the shape.

If you get two intersections, the one furthest away from A is the exit point.

Note that the ray-vs-segment problem can be further decomposed: Simply calculate the intersection of two lines, and see if the point of intersection is at the right side of the ray, and in the right range of the segment.

I'm pretty sure this approach even works if the shape is concave: you just get multiple entry and multiple exit points.

• Unfortunately, I cannot afford to use more than one raycast as it greatly impacts performance, hence why I'm tackling it with math. – Black Scarlet May 4 '18 at 17:47
• Why do you call it a "ray-cast?" line vs line is just one subtract, one mult, one add of a 2d vector. You're not doing a ray-versus-scene or something. – Bram May 4 '18 at 17:59
• Oh, I guess I misunderstood you then. Could you better clarify what you meant? – Black Scarlet May 4 '18 at 21:21