Reputation: 450
I have two circles joined together like this:
And I have a point inside the shape, and I would like to cast a ray in a direction from that point onto the shape. In order to retrieve the casted position on the edge of the shape.
My first thought will be to raycast with the 2 segments joining the 2 circles. And if there is no success hit, I'll raycast with the 2 circles and take the farthest hit position. Is there a better solution? More efficient computation-wise?
Thank you for your answers
Upvotes: 1
Views: 387
Reputation: 80287
Is suppose that you have direction vector of ray D=(dx, dy)
and source point is inside of capsule
If you have central axis, use it's direction vector A, otherwise get direction vector S, S of any segment.
At first decide what segment might be intersected: get cross product A x D
or S x D
and look at it's sign. Positive sign denotes that you have to check only intersection with the "left" segment, negative one - intersection with the "right" segment.
Upvotes: 0