Trying to determine if a tangent is present when a triangle overlaps a circle
In which language? This is really more a mathematical problem than a programming/compilation one. Try walking the circumference of the circle, testing for a point along each of the triangle's segments. If only one such point can be found, or a series of consecutive points (since software "circles" are never true circles, they're made up of short straight segments), then you have a tangent.
You can save a lot of time and math by making coarse estimates first - for example, don't bother testing for tangentiality for any circumferential segment that's fully above, to the left or right of, or below, all three points of the triangle - you CANNOT have a tangent in those areas.
An alternate approach is... walk the triangle instead of walking the circle. Test for a single circle crossing point. Again, you can save time by checking each segment first, and walking only segments that actually cross the circle's circumference. If no part of the circle can be found mathematically between any pair of vertices, then discard that segment outright.
Mar 10, 2014 |
Computers & Internet