public static void DistanceWithinRectangle(double height, Vector2d rectangleCenterLineStart, Vector2d rectangleCenterLineEnd, double rectangleHalfWitdth, double influenceDistance, List <EPMPoint> pointList, CurveMode curveMode = CurveMode.ReverseLinear, CombineMode combineMode = CombineMode.Add, double limitation = 0) { Vector2d dir = rectangleCenterLineEnd - rectangleCenterLineStart; double lineLength = dir.Length(); dir.Normalize(); Vector2d normal = new Vector2d(-dir.y, dir.x); for (int i = 0; i < pointList.Count; i++) { EPMPoint p = pointList[i]; Vector2d v2 = p.pos2d - rectangleCenterLineStart; double hlength = v2 * dir; double vlength = v2 * normal; double distance = 0; if (hlength >= 0 && hlength <= lineLength && System.Math.Abs(vlength) <= rectangleHalfWitdth) { //The point is in the rectangle distance = EPMGlobal.Min(rectangleHalfWitdth - System.Math.Abs(vlength), hlength, lineLength - hlength); if (distance <= influenceDistance) { double y = GetHeightByCurveMode(distance / influenceDistance, curveMode) * height; SetHeightByCombineMode(p, y, combineMode, limitation); } } else { //The point is outside the rectangle, ignore it. continue; } } }
public static void DistanceToBorderOfRectangle(double height, Vector2d rectangleCenterLineStart, Vector2d rectangleCenterLineEnd, double rectangleHalfWitdth, double influenceDistance, List <EPMPoint> pointList, CurveMode curveMode = CurveMode.ReverseLinear, CombineMode combineMode = CombineMode.Add, double limitation = 0) { Vector2d dir = rectangleCenterLineEnd - rectangleCenterLineStart; double lineLength = dir.Length(); dir.Normalize(); Vector2d normal = new Vector2d(-dir.y, dir.x); Vector2d corner1, corner2, corner3, corner4; corner1 = rectangleCenterLineStart + normal * rectangleHalfWitdth; corner2 = rectangleCenterLineStart - normal * rectangleHalfWitdth; corner3 = rectangleCenterLineEnd + normal * rectangleHalfWitdth; corner4 = rectangleCenterLineEnd - normal * rectangleHalfWitdth; for (int i = 0; i < pointList.Count; i++) { EPMPoint p = pointList[i]; Vector2d v2 = p.pos2d - rectangleCenterLineStart; double hlength = v2 * dir; double vlength = v2 * normal; double distance = 0; if (hlength >= 0 && hlength <= lineLength && System.Math.Abs(vlength) <= rectangleHalfWitdth) { //The point is in the rectangle, ignore it. continue; } else { if (hlength >= 0 && hlength <= lineLength) { distance = System.Math.Abs(vlength - rectangleHalfWitdth); } else if (System.Math.Abs(vlength) <= rectangleHalfWitdth) { if (hlength > 0) { distance = hlength - lineLength; } else { distance = -hlength; } } else { v2 = p.pos2d; distance = EPMGlobal.Min((v2 - corner1).Length(), (v2 - corner2).Length(), (v2 - corner3).Length(), (v2 - corner4).Length()); } if (distance <= influenceDistance) { double y = GetHeightByCurveMode(distance / influenceDistance, curveMode) * height; SetHeightByCombineMode(p, y, combineMode, limitation); } } } }