1
votes

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.

2
Could you show own attempts?MBo
@MBo I can't figure out how to do it. I'm still in the brainstorming stage, and haven't put any ideas to test.cToR7

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:

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:

  1. Check squared distances from circle center (CC) to every vertex of triangle

if they are too large:

  1. Check whether CC is inside triangle (using signs of cross-products)

if not:

  1. Calculate projections of CC onto triangle edges (line segments) using scalar products. If projection is inside edge, calculate distance from CC to edge.