static bool Contains(List <ControlPoint> polygon, ControlPoint point) { int alpha = 0; ControlPoint v1 = polygon[polygon.Count - 1]; int q1; if (v1.Y <= point.Y) { if (v1.X <= point.X) { q1 = 0; } else { q1 = 1; } } else if (v1.X <= point.X) { q1 = 3; } else { q1 = 2; } for (int i = 0; i < polygon.Count; i++) { ControlPoint v2 = polygon[i]; int q2; if (v2.Y <= point.Y) { if (v2.X <= point.X) { q2 = 0; } else { q2 = 1; } } else if (v2.X <= point.X) { q2 = 3; } else { q2 = 2; } switch ((q2 - q1) & 3) { case 0: break; case 1: alpha += 1; break; case 3: alpha -= 1; break; default: double zx = ((v2.X - v1.X) * (point.Y - v1.Y) / (v2.Y - v1.Y)) + v1.X; if (point.X - zx == 0) { return(true); } if ((point.X > zx) == (v2.Y > v1.Y)) { alpha -= 2; } else { alpha += 2; } break; } v1 = v2; q1 = q2; } return(Math.Abs(alpha) == 4); }
public Triangle(ControlPoint a, ControlPoint b, ControlPoint c) { A = a; B = b; C = c; }