예제 #1
0
파일: Segment.cs 프로젝트: Anovi-Soft/KGG
 public Vector CrossingPoint(Segment other)
 {
     float x = -((begin.X * end.Y - end.X * begin.Y) * (other.End.X - other.Begin.X) - (other.Begin.X * other.End.Y - other.End.X * other.Begin.Y) * (end.X - begin.X)) / ((begin.Y - end.Y) * (other.End.X - other.Begin.X) - (other.Begin.Y - other.End.Y) * (end.X - begin.X));
     if (x == float.NaN)
         return null;
     float y = ((other.Begin.Y - other.End.Y) * (-x) - (other.Begin.X * other.End.Y - other.End.X * other.Begin.Y)) / (other.End.X - other.Begin.X);
     return new Vector(x, y);
 }
예제 #2
0
파일: MyPolygon.cs 프로젝트: Anovi-Soft/KGG
 public static MyPolygon Intersection(MyPolygon a, Segment b)
 {
     List<Vector> result = new List<Vector>();
     a.points.Add(a.points.First());
     for (int i = 0; i < a.points.Count - 1; i++)
     {
         Vector start = a.points[i];
         Vector end = a.points[i + 1];
         bool s = b.PlaceOfPoint(start) <= 0; //справа
         bool e = b.PlaceOfPoint(end) <= 0; 
         if (s)
             result.Add(start);
         if (s ^ e)
             result.Add(b.CrossingPoint(new Segment(start, end)));
     }
     return new MyPolygon(result);
 }