Search code examples
c#intersectioneyeshot

Intersection of Entities


I want to create a while loop to Translate some entities which have intersections with each other. But the Entity.Intersects() method is protected. Is there any other solution to find intersections with Eyeshot methods? My entities are Region in XY-Plane. (I also tried UtilityEx.DoOverlap(Mesh, Mesh) by converting my regions to mesh, and it didn't work, since I can see the overlapping area of my entities in my Eyeshot Model.)

public static void MoveIntersectedEntity(List<Mesh> mainList, ref Mesh movingMesh, bool moveUp = false)
{
   for (int i = 0; i < mainList.Count; i++)
    {
      while (UtilityEx.DoOverlap(mainList[i],movingMesh))
        {
          if (moveUp)
            movingMesh.Translate(0,2,0);
          else
            movingMesh.Translate(0,-2,0);
        }
    }
}

Solution

  • I actually found my answer. The Region class has a method of intersection that will return an array if there was an intersection between two regions.

    Region[] result = Region.Intersection(region_1, region_2);
    
    public static T[] Intersection<T>( 
       T a, 
       T b 
    ) 
       where T : Region, new()
    

    If the result.Length > 0 then we have an intersection.