/// <summary> /// Extends a straight line at both ends /// </summary> /// <param name="line"></param> /// <param name="distance"></param> /// <search></search> public static Autodesk.DesignScript.Geometry.Line ExtendAtBothEnds(this Autodesk.DesignScript.Geometry.Curve line, double distance) { Autodesk.DesignScript.Geometry.Point stPt = line.StartPoint; Autodesk.DesignScript.Geometry.Point endPt = line.EndPoint; Autodesk.DesignScript.Geometry.Vector vec1 = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(endPt, stPt); Autodesk.DesignScript.Geometry.Vector vec2 = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(stPt, endPt); Autodesk.DesignScript.Geometry.Point newStPt = stPt.Translate(vec1, distance) as Autodesk.DesignScript.Geometry.Point; Autodesk.DesignScript.Geometry.Point newEndPt = endPt.Translate(vec2, distance) as Autodesk.DesignScript.Geometry.Point; Autodesk.DesignScript.Geometry.Line newLine = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(newStPt, newEndPt); //Dispose redundant geometry stPt.Dispose(); endPt.Dispose(); vec1.Dispose(); vec2.Dispose(); newStPt.Dispose(); newEndPt.Dispose(); return(newLine); }
/// <summary> /// Compares a single curve to a list of curves to find any curves that have the same normalised vector. /// </summary> /// <param name="curve"></param> /// <param name="curves"></param> /// <search></search> public static List <Autodesk.DesignScript.Geometry.Curve> FindMatchingVectorCurves(this Autodesk.DesignScript.Geometry.Curve curve, List <Autodesk.DesignScript.Geometry.Curve> curves) { Autodesk.DesignScript.Geometry.Point stPt1 = curve.StartPoint; Autodesk.DesignScript.Geometry.Point endPt1 = curve.EndPoint; Autodesk.DesignScript.Geometry.Vector vec1 = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(stPt1, endPt1).Normalized(); string str1 = vec1.ToString(); List <string> curveList = new List <string>(); foreach (var c in curves) { Autodesk.DesignScript.Geometry.Point stPt2 = c.StartPoint; Autodesk.DesignScript.Geometry.Point endPt2 = c.EndPoint; Autodesk.DesignScript.Geometry.Vector vec2 = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(stPt2, endPt2).Normalized(); string str2 = vec2.ToString(); curveList.Add(str2); //Dispose redundant geometry stPt2.Dispose(); endPt2.Dispose(); vec2.Dispose(); } List <Autodesk.DesignScript.Geometry.Curve> matchingCurves = new List <Autodesk.DesignScript.Geometry.Curve>(); for (int i = 0; i < curveList.Count; i++) { if (str1 == curveList[i]) { matchingCurves.Add(curves[i]); } } if (matchingCurves.Count == 0) { List <string> revCurveList = new List <string>(); foreach (var c in curves) { Autodesk.DesignScript.Geometry.Point stPt2 = c.StartPoint; Autodesk.DesignScript.Geometry.Point endPt2 = c.EndPoint; Autodesk.DesignScript.Geometry.Vector vec2 = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(endPt2, stPt2).Normalized(); string str2 = vec2.ToString(); revCurveList.Add(str2); //Dispose redundant geometry stPt2.Dispose(); endPt2.Dispose(); vec2.Dispose(); } for (int i = 0; i < revCurveList.Count; i++) { if (str1 == revCurveList[i]) { matchingCurves.Add(curves[i]); } } } //Dispose redundant geometry stPt1.Dispose(); endPt1.Dispose(); vec1.Dispose(); return(matchingCurves); }