/// <summary> /// The perpendicular distance of the infinite line defined by the Start/End points of this /// line to the specified point. /// </summary> /// <param name="point"></param> /// <returns></returns> public double GetDistancePerpendicular(Pnt3D point) { var sp = new Line3D(StartPoint, point); Vector vectorProduct = GeomUtils.CrossProduct(DirectionVector, sp.DirectionVector); return(Math.Abs(vectorProduct.Length / DirectionVector.Length)); }
public bool IsParallel(Plane3D other) { double e = Math.Max(Epsilon, other.Epsilon); Vector crossProduct = GeomUtils.CrossProduct(Normal, other.Normal); return(MathUtils.AreEqual(crossProduct.X, 0, e) && MathUtils.AreEqual(crossProduct.Y, 0, e) && MathUtils.AreEqual(crossProduct[2], 0, e)); }
public double GetArea2D() { if (!IsClosed) { throw new NotImplementedException( "Area can only be calculated for closed linestrings."); } return(GeomUtils.GetArea2D(GetPoints().ToList())); }
public double GetDistanceSigned(double x, double y, double z) { if (!IsDefined) { throw new InvalidOperationException("Plane is not defined."); } var v = new Pnt3D(x, y, z); double dotProd = GeomUtils.DotProduct(v, A, B, C); return((dotProd - D) / LengthOfNormal); }
private static Vector OrientNormal([NotNull] Vector normal, [NotNull] IList <Pnt3D> points, bool isRing) { if (isRing) { double area3D = GeomUtils.GetArea3D(points, new Pnt3D(normal)); if (area3D < 0) { normal *= -1; } } return(normal); }
public double?GetIntersectionFactor(Pnt3D lineStart, Pnt3D lineEnd) { if (!IsDefined) { throw new InvalidOperationException("Plane is not defined."); } // Required: any point on the plane p: var p = new Pnt3D(Normal * D / LengthOfNormalSquared); double denominator = GeomUtils.DotProduct(lineEnd - lineStart, Normal); if (MathUtils.AreEqual(denominator, 0)) { // The line is parallel to the plane. return(null); } double t = GeomUtils.DotProduct(p - lineStart, Normal) / denominator; return(t); }
private static bool IsBelowThreshold(Pnt3D sourcePoint, Pnt3D touchPoint, Pnt3D nonIntersectingTargetPnt, double tolerance) { // Target starts (just?) after source, target touches source interior //Pnt3D touchPoint = targetLine.GetPointAlong(_source1Factor, true); double distanceFromStartToTouchPoint = touchPoint.GetDistance(sourcePoint, true); double alpha = GeomUtils.GetAngle2DInRad(sourcePoint, touchPoint, nonIntersectingTargetPnt); if (alpha < Math.PI / 2) // smaller 90° { double threshold = tolerance / Math.Sin(alpha); if (distanceFromStartToTouchPoint < threshold) { return(true); } } return(false); }
/// <summary> /// The perpendicular distance of the infinite line defined by the Start/End points of this /// line to the specified point. /// </summary> /// <param name="point"></param> /// <param name="inXY"></param> /// <param name="distanceAlongRatio">The distance-along-ratio of the closest point on the line.</param> /// <param name="pointOnLine"></param> /// <returns></returns> public double GetDistancePerpendicular(Pnt3D point, bool inXY, out double distanceAlongRatio, out Pnt3D pointOnLine) { // http://geomalgorithms.com/a02-_lines.html#Distance-to-Infinite-Line Pnt3D w = point - StartPoint; double c1, c2; if (inXY) { c1 = GeomUtils.DotProduct(w.X, w.Y, 0, DirectionVector.X, DirectionVector.Y, 0); c2 = DirectionVector.Length2DSquared; } else { c1 = GeomUtils.DotProduct(w, DirectionVector); c2 = DirectionVector.LengthSquared; } if (c2 < double.Epsilon) { // 0-length line: Distance to StartPoint distanceAlongRatio = 0; pointOnLine = (Pnt3D)StartPoint.Clone(); return(StartPoint.GetDistance(point, inXY)); } distanceAlongRatio = c1 / c2; pointOnLine = (Pnt3D)(StartPoint + distanceAlongRatio * DirectionVector); return(pointOnLine.GetDistance(point, inXY)); }
public double GetMaxExtent() { return(GetMaxExtent(GeomUtils.GetDimensionList(Dimension))); }
public int ExceedDimension([NotNull] IBox box) { return(ExceedDimension(box, GeomUtils.GetDimensionList(Dimension))); }
public bool Intersects(IBox box) { return(Intersects(box, GeomUtils.GetDimensionList(Dimension))); }
/// <summary> /// Indicates if box is within this /// </summary> /// <param name="box"></param> /// <returns></returns> public bool Contains(IBox box) { return(Contains(box, GeomUtils.GetDimensionList(Dimension))); }
public bool Contains(IPnt p) { return(Contains(p, GeomUtils.GetDimensionList(Dimension))); }