private bool IsPointInsideDomain(Vector2f coordinate) { bool result = false; Vector2f origin = new Vector2f(-100000, -100000); float minDist = int.MaxValue; int nbIntersect = 0; for (int i = 0; i < this.domainPoints.Count; i++) { Vector2f point1 = this.domainPoints[i]; Vector2f point2; if (i == this.domainPoints.Count - 1) { point2 = this.domainPoints[0]; } else { point2 = this.domainPoints[i + 1]; } float num1 = point1.X * point2.Y - point1.Y * point2.X; float num2 = origin.X * coordinate.Y - origin.Y * coordinate.X; float denum = (point1.X - point2.X) * (origin.Y - coordinate.Y) - (point1.Y - point2.Y) * (origin.X - coordinate.X); if (denum != 0) { float intersecX = (num1 * (origin.X - coordinate.X) - num2 * (point1.X - point2.X)) / denum; float intersecY = (num1 * (origin.Y - coordinate.Y) - num2 * (point1.Y - point2.Y)) / denum; Vector2f intersect = new Vector2f(intersecX, intersecY); if (intersect != point2 && (intersect - point1).Dot(intersect - point2) < 0 && (intersect - origin).Dot(intersect - coordinate) < 0) { nbIntersect++; } } Vector2f firstVector = coordinate - point1; Vector2f normalizedEdge = (point2 - point1).Normalize(); //vec2 vector = vector - normalizedEdge * dot(normalizedEdge, vector); //vec3 crossVector = cross(vec3(firstVector, 0), vec3(normalizedEdge, 0)); //vec3 crossVector2 = cross(vec3(vector2, 0), vec3(-normalizedEdge, 0)); Vector2f secondVector = coordinate - point2; if (normalizedEdge.Dot(firstVector) * normalizedEdge.Dot(secondVector) < 0) { float crossLen = Math.Abs(firstVector.CrossZ(normalizedEdge)); if (crossLen < minDist) { minDist = crossLen; } } float lenToPoint = firstVector.Len(); if (lenToPoint < minDist) { minDist = lenToPoint; } } if (this.isFilled) { if (nbIntersect % 2 == 1) { result = true; } } if (minDist < MARGIN_DOMAIN / 2) { result = true; } return(result); }