0

'Ring parts' are sections cut out of a ring.

Each 'ring part' is represented by a center point, and then some bounds relative to that center point.

Inner and outer distance bounds define a 2D ring, first of all, and then a pair of angular bounds define a start and end cut off around this ring. (I am specifying the angular bounds in the form of a start angle and then a sweep angle, but exactly what form this takes is not so important.)

How can I test for geometric intersection between two such 'ring parts', whilst keeping the code that tests for this as simple and robust as possible?

I tried an approach based on first detecting the various cases for intersection between rings, (i.e. initially ignoring the angular bounds) and then checking whether the intersecting part falls inside the angular bounds. I thought it might be possible to reduce the information needed about the intersecting part of the rings to angle extents, but I don't think this works in all cases.

I also thought about an initial step of cutting (or clipping) one ring part along the radial bound lines of the other. I think this might be a reasonable way to go, but clipping a shape with curved edges in itself starts to get a bit complicated.

Martin Půda
  • 7,353
  • 2
  • 6
  • 13
Thomas Young
  • 193
  • 3
  • 9

2 Answers2

2

Contour of a 'ring part' is composed of 4 parts {2 circular arcs and 2 line segments}.
So, I guess, you can check the intersection step by step.

i.e. checking "contour part vs contour part intersection". This becomes

  • "circular arc vs circular arc"
  • "circular arc vs line segments"
  • "line segment vs line segment"

I guess you can solve all of them.

Also, if you want to check "One is completely inside of the another" pattern, you'll be able to check it with "Is any corner point of one 'ring part' inside the another". (where, 'corner points' is end points of the contour parts. one 'ring part' has 4 corner points.)

fana
  • 1,370
  • 2
  • 7
0

To test intersection of two ring sectors, you need to check if 1) their radii intervals intersect and 2) their angular intervals intersect

Let ring sector is defined by inner and outer radii ri, ro, start angle astart and sweep angle sw:

Intersection along radius:

 not (ri1>ro2 or ri2>ro1)
   equivalent:
 (ri1<=ro2 and ri2<=ro1) 

angular interval intersection is more complex because we should account for periodicity. Let find middle angle ma and cosine of half-sweep cd (cosine usage solves problems with periodicity, distinct arc directions and so on)

ma = astart + sw/2
cd = Cos(sw/2)

Then angular intervals intersect if

Cos(ma1 - astart2) >= cd1  or 
Cos(ma1 - astart2 - sw2) >= cd1  or 
Cos(ma2 - astart1) >= cd2  or 
Cos(ma2 - astart1 - sw1) >= cd2
MBo
  • 77,366
  • 5
  • 53
  • 86