/// <summary> /// Warning, this suffers from FP tolerance issues, /// when the polygon has arc segments with very large radii (for instance). /// </summary> public bool IsPointInside(Vector3D p) { // ZZZ - Our "ray" will be half a circle for now. // (We'll throw out intersections where x <= p.X) Circle ray = new Circle(); //ray.From3Points( p + new Vector3D( -500, 1 ), p, p + new Vector3D( 500, 1 ) ); // Circle was too huge (r ~= 125000), which caused tolerance issues. //ray.From3Points( p + new Vector3D( -103, 1 ), p, p + new Vector3D( 193, 1 ) ); // primes! (r ~= 10000) Still suffering ray.From2Points(p, p + new Vector3D(10007, 103)); // Best, but still not perfect. return(IsPointInside(p, ray)); }
/// <summary> /// Try not to use this. /// See IsInverted method about this HACK. /// ZZZ - Need to find a better way to make IsPointInside more robust :( /// </summary> public bool IsPointInsideParanoid(Vector3D p) { int insideCount = 0; Circle ray = new Circle(); if (this.IsPointInside(p)) { insideCount++; } ray.From2Points(p, p + new Vector3D(103, 10007)); if (this.IsPointInside(p, ray)) { insideCount++; } ray.From2Points(p, p + new Vector3D(7001, 7993)); if (this.IsPointInside(p, ray)) { insideCount++; } return(insideCount >= 2); }