/// <summary> /// Gets direction of the line segment (Normalized) /// </summary> /// <param name="src">Line segment</param> /// <returns>Direction</returns> public static WM.Vector3D GetDirection(this ILineSegment3D src) { var temp = new WM.Vector3D(src.EndPoint.X - src.StartPoint.X, src.EndPoint.Y - src.StartPoint.Y, src.EndPoint.Z - src.StartPoint.Z); temp.Normalize(); return(temp); }
/// <summary> /// Convert the points of segment based on baseGeometry /// </summary> /// <param name="matrix">LCS matrix of baseGeometry</param> /// <param name="baseGeometry">Based on this region, the given segment is modifed</param> /// <param name="segment">Input segment object</param> /// <param name="isIndependent">Segment is independent</param> /// <param name="modifyInput">If true, given segment object is modified. Otherwise prepare new segment object</param> /// <returns>Segment object which is based on baseGeometry</returns> public static ISegment3D GetSegmentOnRegion(IMatrix44 matrix, IRegion3D baseGeometry, ISegment3D segment, bool isIndependent = true, bool modifyInput = true) { if (baseGeometry == null || segment == null) { return(null); } if (matrix == null) { matrix = GetMatrixPlane(baseGeometry); } if (!modifyInput) { segment = segment.CloneSegment(); } ILineSegment3D line = segment as ILineSegment3D; if (line != null) { if (isIndependent) { line.StartPoint = GetPointOnRegion(matrix, baseGeometry, line.StartPoint); } line.EndPoint = GetPointOnRegion(matrix, baseGeometry, line.EndPoint); return(line); } IArcSegment3D arc = segment as IArcSegment3D; if (arc != null) { if (isIndependent) { arc.StartPoint = GetPointOnRegion(matrix, baseGeometry, arc.StartPoint); } arc.IntermedPoint = GetPointOnRegion(matrix, baseGeometry, arc.IntermedPoint); arc.EndPoint = GetPointOnRegion(matrix, baseGeometry, arc.EndPoint); return(arc); } throw new NotSupportedException(); }
/// <summary> /// Calculates intersection of the plane and line <paramref name="lineSeg"/> /// </summary> /// <param name="src">Plane</param> /// <param name="lineSeg">Line segment</param> /// <returns></returns> public static WM.Point3D GetIntersection(this Plane3D src, ILineSegment3D lineSeg) { var l = new WM.Vector3D(lineSeg.EndPoint.X - lineSeg.StartPoint.X, lineSeg.EndPoint.Y - lineSeg.StartPoint.Y, lineSeg.EndPoint.Z - lineSeg.StartPoint.Z); l.Normalize(); double d = WM.Vector3D.DotProduct(src.NormalVector, l); if (d.IsZero()) { return(new WM.Point3D(double.NaN, double.NaN, double.NaN)); } WM.Point3D l0 = lineSeg.StartPoint.ToMediaPoint(); double dd = WM.Vector3D.DotProduct((src.PointOnPlane - l0), src.NormalVector) / d; return(l0 + dd * l); }
/// <summary> /// Create a Line segment from another line segment /// </summary> /// <param name="source">Source line segment</param> public LineSegment3D(ILineSegment3D source) : base(source) { Name = (source as ElementBase).Name; }
public static void Move(ILineSegment3D segment, WM.Vector3D displacement) { segment.StartPoint.Add(ref displacement); segment.EndPoint.Add(ref displacement); }