1
\$\begingroup\$

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

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. enter image description here

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

enter image description here

Any help is greatly appreciated :D

\$\endgroup\$
2
  • \$\begingroup\$ 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? \$\endgroup\$ Commented May 4, 2018 at 11:32
  • \$\begingroup\$ 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 :) \$\endgroup\$ Commented May 4, 2018 at 11:58

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ Unfortunately, I cannot afford to use more than one raycast as it greatly impacts performance, hence why I'm tackling it with math. \$\endgroup\$ Commented May 4, 2018 at 17:47
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ Commented May 4, 2018 at 17:59
  • \$\begingroup\$ Oh, I guess I misunderstood you then. Could you better clarify what you meant? \$\endgroup\$ Commented May 4, 2018 at 21:21

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.