This is needed for a program I am working now. The only information I have to work with is the coordinates of the vertices of a triangle, the coordinates of the center of the circle and the diameter of the circle. How would I figure out if a circle is touching/intersecting a triangle in a 2 dimensional space? I am using Processing.
1
votes
2 Answers
1
votes
Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense:
The best thing you can do is Google stuff like circle triangle intersection or circle triangle collision detection. You'll find a ton of results, including:
- https://math.stackexchange.com/questions/867627/intersection-of-a-circle-and-a-triangle
- How to get collision detection of circle and triangle
- https://www.gamedev.net/forums/topic/406403-circle-in-triangle-intersection/
The point is, you shouldn't be afraid to do some research. Try to put together a small example program (aka a MCVE) and ask a more specific question if you get stuck. Good luck.
0
votes
Steps:
- Check squared distances from circle center (CC) to every vertex of triangle
if they are too large:
- Check whether CC is inside triangle (using signs of cross-products)
if not:
- Calculate projections of CC onto triangle edges (line segments) using scalar products. If projection is inside edge, calculate distance from CC to edge.