Class Line
A line segment. Parameterization of the line is 0 (start) -> length (end)
Examples
var a = new Vector3();
var b = new Vector3(5, 5, 5);
var l = new Line(a, b);
Implements
Inherited Members
Namespace: Elements.Geometry
Assembly: Hypar.Elements.dll
Syntax
public class Line : TrimmedCurve<InfiniteLine>, ICurve, ITransformable<Curve>, IBoundedCurve, ITrimmedCurve<InfiniteLine>, IEquatable<Line>
Constructors
Line()
Create a line of one unit length along the X axis.
Declaration
public Line()
Line(InfiniteLine)
Create a line from a trimmed segment of an infinite line.
Declaration
public Line(InfiniteLine line)
Parameters
Type | Name | Description |
---|---|---|
InfiniteLine | line | The infinite line from which this segment is trimmed. |
Line(Vector3, Vector3)
Create a line.
Declaration
[JsonConstructor]
public Line(Vector3 start, Vector3 end)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | start | The start of the line. |
Vector3 | end | The end of the line. |
Line(Vector3, Vector3, Double)
Create a line of length from a start along direction.
Declaration
public Line(Vector3 start, Vector3 direction, double length)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | start | |
Vector3 | direction | |
System.Double | length |
Properties
Domain
The domain of the curve.
Declaration
[JsonIgnore]
public override Domain1d Domain { get; }
Property Value
Type | Description |
---|---|
Domain1d |
Overrides
Methods
ArcLength(Double, Double)
Calculate the length of the line between two parameters.
Declaration
public override double ArcLength(double start, double end)
Parameters
Type | Name | Description |
---|---|---|
System.Double | start | |
System.Double | end |
Returns
Type | Description |
---|---|
System.Double |
Overrides
BestFit(IList<Vector3>)
Return an approximate fit line through a set of points using the least squares method.
Declaration
public static Line BestFit(IList<Vector3> points)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<Vector3> | points | The points to fit. Should have at least 2 distinct points. |
Returns
Type | Description |
---|---|
Line | An approximate fit line through a set of points using the least squares method. If there is less than 2 distinct points, returns null. |
Bounds()
Get the bounding box for this line.
Declaration
public override BBox3 Bounds()
Returns
Type | Description |
---|---|
BBox3 | A bounding box for this line. |
Overrides
Direction()
A normalized vector representing the direction of the line.
Declaration
public Vector3 Direction()
Returns
Type | Description |
---|---|
Vector3 |
Direction(Vector3, Vector3)
A normalized vector representing the direction of a line, represented by a start and end point.
The start point of the line. The end point of the line.Declaration
public static Vector3 Direction(Vector3 start, Vector3 end)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | start | |
Vector3 | end |
Returns
Type | Description |
---|---|
Vector3 |
DistanceTo(Line)
Measure the distance between two lines.
Declaration
public double DistanceTo(Line other)
Parameters
Type | Name | Description |
---|---|---|
Line | other | The line to measure the distance to. |
Returns
Type | Description |
---|---|
System.Double |
DivideByLength(Double, Boolean)
Divide the line into as many segments of the provided length as possible.
Declaration
public List<Line> DivideByLength(double l, bool removeShortSegments = false)
Parameters
Type | Name | Description |
---|---|---|
System.Double | l | The length. |
System.Boolean | removeShortSegments | A flag indicating whether segments shorter than l should be removed. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<Line> |
DivideByLengthFromCenter(Double)
Divide the line into as many segments of the provided length as possible. Divisions will be centered along the line.
Declaration
public List<Line> DivideByLengthFromCenter(double l)
Parameters
Type | Name | Description |
---|---|---|
System.Double | l | The length. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<Line> |
DivideIntoEqualSegments(Int32)
Divide the line into n equal segments.
Declaration
public List<Line> DivideIntoEqualSegments(int n)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | The number of segments. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<Line> |
Equals(Line)
Is this line equal to the provided line?
Declaration
public bool Equals(Line other)
Parameters
Type | Name | Description |
---|---|---|
Line | other | The target line. |
Returns
Type | Description |
---|---|
System.Boolean | True if the start and end points of the lines are equal, otherwise false. |
ExtendTo(Line)
Extend this line to the trimming curve.
Declaration
public Line ExtendTo(Line line)
Parameters
Type | Name | Description |
---|---|---|
Line | line | The curve to which to extend. |
Returns
Type | Description |
---|---|
Line | A new line, or null if these lines would never intersect if extended infinitely. |
ExtendTo(Polygon, Boolean, Boolean, Double)
Extend this line to its (nearest, by default) intersection with a polygon.
Declaration
public Line ExtendTo(Polygon polygon, bool bothSides = true, bool extendToFurthest = false, double tolerance = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
Polygon | polygon | The polygon to intersect with |
System.Boolean | bothSides | Optional — if false, will only extend in the line's direction; if true will extend in both directions. |
System.Boolean | extendToFurthest | Optional — if true, will extend line as far as it will go, rather than stopping at the closest intersection. |
System.Double | tolerance | Optional — The amount of tolerance to include in the extension method. |
Returns
Type | Description |
---|---|
Line |
ExtendTo(Polygon, Double, Boolean, Boolean, Double)
Extend this line to its (nearest, by default) intersection with a polygon, but no further than maxDistance.
Declaration
public Line ExtendTo(Polygon polygon, double maxDistance, bool bothSides = true, bool extendToFurthest = false, double tolerance = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
Polygon | polygon | The polygon to intersect with |
System.Double | maxDistance | Maximum extension distance. |
System.Boolean | bothSides | Optional — if false, will only extend in the line's direction; if true will extend in both directions. |
System.Boolean | extendToFurthest | Optional — if true, will extend line as far as it will go, rather than stopping at the closest intersection. |
System.Double | tolerance | Optional — The amount of tolerance to include in the extension method. |
Returns
Type | Description |
---|---|
Line |
ExtendTo(Polyline, Boolean, Boolean)
Extend this line to its (nearest, by default) intersection with a polyline.
Declaration
public Line ExtendTo(Polyline polyline, bool bothSides = true, bool extendToFurthest = false)
Parameters
Type | Name | Description |
---|---|---|
Polyline | polyline | The polyline to intersect with |
System.Boolean | bothSides | Optional — if false, will only extend in the line's direction; if true will extend in both directions. |
System.Boolean | extendToFurthest | Optional — if true, will extend line as far as it will go, rather than stopping at the closest intersection. |
Returns
Type | Description |
---|---|
Line |
ExtendTo(Polyline, Double, Boolean, Boolean)
Extend this line to its (nearest, by default) intersection with a polyline, but no further than maxDistance.
Declaration
public Line ExtendTo(Polyline polyline, double maxDistance, bool bothSides = true, bool extendToFurthest = false)
Parameters
Type | Name | Description |
---|---|---|
Polyline | polyline | The polyline to intersect with |
System.Double | maxDistance | Maximum extension distance. |
System.Boolean | bothSides | Optional — if false, will only extend in the line's direction; if true will extend in both directions. |
System.Boolean | extendToFurthest | Optional — if true, will extend line as far as it will go, rather than stopping at the closest intersection. |
Returns
Type | Description |
---|---|
Line |
ExtendTo(Profile, Boolean, Boolean)
Extend this line to its (nearest, by default) intersection with a profile.
Declaration
public Line ExtendTo(Profile profile, bool bothSides = true, bool extendToFurthest = false)
Parameters
Type | Name | Description |
---|---|---|
Profile | profile | The profile to intersect with |
System.Boolean | bothSides | Optional — if false, will only extend in the line's direction; if true will extend in both directions. |
System.Boolean | extendToFurthest | Optional — if true, will extend line as far as it will go, rather than stopping at the closest intersection. |
Returns
Type | Description |
---|---|
Line |
ExtendTo(Profile, Double, Boolean, Boolean)
Extend this line to its (nearest, by default) intersection with a profile, but no further than maxDistance.
Declaration
public Line ExtendTo(Profile profile, double maxDistance, bool bothSides = true, bool extendToFurthest = false)
Parameters
Type | Name | Description |
---|---|---|
Profile | profile | The profile to intersect with |
System.Double | maxDistance | Maximum extension distance. |
System.Boolean | bothSides | Optional — if false, will only extend in the line's direction; if true will extend in both directions. |
System.Boolean | extendToFurthest | Optional — if true, will extend line as far as it will go, rather than stopping at the closest intersection. |
Returns
Type | Description |
---|---|
Line |
ExtendTo(IEnumerable<Line>, Boolean, Boolean, Double)
Extend this line to its (nearest, by default) intersection with any other line.
If optional extendToFurthest
is true, extends to furthest intersection with any other line.
Declaration
public Line ExtendTo(IEnumerable<Line> otherLines, bool bothSides = true, bool extendToFurthest = false, double tolerance = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Line> | otherLines | The other lines to intersect with |
System.Boolean | bothSides | Optional — if false, will only extend in the line's direction; if true will extend in both directions. |
System.Boolean | extendToFurthest | Optional — if true, will extend line as far as it will go, rather than stopping at the closest intersection. |
System.Double | tolerance | Optional — The amount of tolerance to include in the extension method. |
Returns
Type | Description |
---|---|
Line |
ExtendTo(IEnumerable<Line>, Double, Boolean, Boolean, Double)
Extend this line to its (nearest, by default) intersection with any other line, but no further than maxDistance.
If optional extendToFurthest
is true, extends to furthest intersection with any other line, but no further than maxDistance.
If the distance to the intersection with the lines is greater than the maximum, the line will be returned unchanged.
Declaration
public Line ExtendTo(IEnumerable<Line> otherLines, double maxDistance, bool bothSides = true, bool extendToFurthest = false, double tolerance = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Line> | otherLines | The other lines to intersect with. |
System.Double | maxDistance | Maximum extension distance. |
System.Boolean | bothSides | Optional — if false, will only extend in the line's direction; if true will extend in both directions. |
System.Boolean | extendToFurthest | Optional — if true, will extend line as far as it will go, rather than stopping at the closest intersection. |
System.Double | tolerance | Optional — The amount of tolerance to include in the extension method. |
Returns
Type | Description |
---|---|
Line |
Fillet(Line, Double)
Create a fillet arc between this line and the target.
Declaration
public Arc Fillet(Line target, double radius)
Parameters
Type | Name | Description |
---|---|---|
Line | target | The line with which to fillet. |
System.Double | radius | The radius of the fillet. |
Returns
Type | Description |
---|---|
Arc | An arc, or null if no fillet can be calculated. |
GetHashCode()
Get the hash code for the line.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
GetParameterAt(Vector3)
Calculate U parameter for point on line
Declaration
public double GetParameterAt(Vector3 point)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | point | Point on line |
Returns
Type | Description |
---|---|
System.Double | Returns U parameter for point on line |
GetParameterAt(Vector3, Vector3, Vector3)
Calculate U parameter for point between two other points
Declaration
public static double GetParameterAt(Vector3 point, Vector3 start, Vector3 end)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | point | Point for which parameter is calculated |
Vector3 | start | First point |
Vector3 | end | Second point |
Returns
Type | Description |
---|---|
System.Double | Returns U parameter for point between two other points |
GetSubdivisionParameters(Double, Double)
Get parameters to be used to find points along the curve for visualization.
Declaration
public override double[] GetSubdivisionParameters(double startSetbackDistance = 0, double endSetbackDistance = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Double | startSetbackDistance | An optional setback from the start of the curve. |
System.Double | endSetbackDistance | An optional setback from the end of the curve. |
Returns
Type | Description |
---|---|
System.Double[] | A collection of parameter values. |
Overrides
Intersects(BBox3, out List<Vector3>, Boolean, Double)
Does this line touches or intersects the provided box in 3D?
Declaration
public bool Intersects(BBox3 box, out List<Vector3> results, bool infinite = false, double tolerance = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
BBox3 | box | Axis aligned box to intersect. |
System.Collections.Generic.List<Vector3> | results | Up to two intersection points. |
System.Boolean | infinite | Treat the line as infinite? |
System.Double | tolerance | An optional distance tolerance. |
Returns
Type | Description |
---|---|
System.Boolean | True if the line touches or intersects the box at least at one point, false otherwise. |
Intersects(Line, out Vector3, Boolean, Boolean)
Does this line intersect the provided line in 3D?
Declaration
public bool Intersects(Line l, out Vector3 result, bool infinite = false, bool includeEnds = false)
Parameters
Type | Name | Description |
---|---|---|
Line | l | |
Vector3 | result | |
System.Boolean | infinite | Treat the lines as infinite? |
System.Boolean | includeEnds | If the end of one line lies exactly on the other, count it as an intersection? |
Returns
Type | Description |
---|---|
System.Boolean | True if the lines intersect, false if they are fully collinear or do not intersect. |
Intersects(Plane, Vector3, Vector3, out Vector3, Boolean)
Intersect a segment defined by two points with a plane.
Declaration
public static bool Intersects(Plane p, Vector3 start, Vector3 end, out Vector3 result, bool infinite = false)
Parameters
Type | Name | Description |
---|---|---|
Plane | p | The plane. |
Vector3 | start | The start of the segment. |
Vector3 | end | The end of the segment. |
Vector3 | result | The location of intersection. |
System.Boolean | infinite | Whether the segment should instead be considered infinite. |
Returns
Type | Description |
---|---|
System.Boolean | True if an intersection is found, otherwise false. |
Intersects(Plane, out Vector3, Boolean)
Intersect this line with the specified plane
Declaration
public bool Intersects(Plane p, out Vector3 result, bool infinite = false)
Parameters
Type | Name | Description |
---|---|---|
Plane | p | The plane. |
Vector3 | result | The location of intersection. |
System.Boolean | infinite | If true, line will be treated as infinite. (False by default) |
Returns
Type | Description |
---|---|
System.Boolean | True if the line intersects the plane, false if no intersection occurs. |
Intersects(Vector3, Vector3, Vector3, Vector3, out Vector3, Boolean, Boolean)
Do two lines intersect in 3d?
Declaration
public static bool Intersects(Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2, out Vector3 result, bool infinite = false, bool includeEnds = false)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | start1 | Start point of the first line |
Vector3 | end1 | End point of the first line |
Vector3 | start2 | Start point of the second line |
Vector3 | end2 | End point of the second line |
Vector3 | result | |
System.Boolean | infinite | Treat the lines as infinite? |
System.Boolean | includeEnds | If the end of one line lies exactly on the other, count it as an intersection? |
Returns
Type | Description |
---|---|
System.Boolean | True if the lines intersect, false if they are fully collinear or do not intersect. |
Intersects2D(Line)
Does this line intersect the provided line in 2D?
Declaration
public bool Intersects2D(Line l)
Parameters
Type | Name | Description |
---|---|---|
Line | l |
Returns
Type | Description |
---|---|
System.Boolean | Return true if the lines intersect, false if the lines have coincident vertices or do not intersect. |
Intersects2d(Vector3, Vector3, Vector3, Vector3)
Does the first line intersect with the second line in 2D?
Declaration
public static bool Intersects2d(Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | start1 | Start point of the first line |
Vector3 | end1 | End point of the first line |
Vector3 | start2 | Start point of the second line |
Vector3 | end2 | End point of the second line |
Returns
Type | Description |
---|---|
System.Boolean | Return true if the lines intersect, false if the lines have coincident vertices or do not intersect. |
IsAlmostEqualTo(Line, Boolean, Double)
Are the two lines almost equal?
Declaration
public bool IsAlmostEqualTo(Line other, bool directionDependent, double tolerance = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
Line | other | |
System.Boolean | directionDependent | |
System.Double | tolerance |
Returns
Type | Description |
---|---|
System.Boolean |
IsCollinear(Line, Double)
Check if this line is collinear with another line.
Declaration
public bool IsCollinear(Line line, double tolerance = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
Line | line | Line to check. |
System.Double | tolerance | If points are within this distance of a fit line, they will be considered collinear. |
Returns
Type | Description |
---|---|
System.Boolean |
IsOnPlane(Plane, Double)
Checks if line lays on plane
Declaration
public bool IsOnPlane(Plane plane, double tolerance = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
Plane | plane | Plane to check |
System.Double | tolerance | Optional tolerance value |
Returns
Type | Description |
---|---|
System.Boolean | The result of check if line lays on plane |
Length()
Calculate the length of the line.
Declaration
public override double Length()
Returns
Type | Description |
---|---|
System.Double |
Overrides
MergedCollinearLine(Line)
Creates new line with vertices of current and joined line
Declaration
public Line MergedCollinearLine(Line line)
Parameters
Type | Name | Description |
---|---|---|
Line | line | Collinear line |
Returns
Type | Description |
---|---|
Line | New line containing vertices of all merged lines |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Throws exception when lines are not collinear |
Mid()
The point at the middle of the curve's parameter space.
Declaration
public override Vector3 Mid()
Returns
Type | Description |
---|---|
Vector3 |
Overrides
Offset(Double, Boolean)
Offset the line. The offset direction will be defined by Direction X Vector3.ZAxis.
Declaration
public Line Offset(double distance, bool flip)
Parameters
Type | Name | Description |
---|---|---|
System.Double | distance | The distance to offset. |
System.Boolean | flip | Flip the offset direction. |
Returns
Type | Description |
---|---|
Line |
ParameterAtDistanceFromParameter(Double, Double)
Get the parameter at a distance from the start parameter along the curve.
Declaration
public override double ParameterAtDistanceFromParameter(double distance, double start)
Parameters
Type | Name | Description |
---|---|---|
System.Double | distance | The distance from the start parameter. |
System.Double | start | The parameter from which to measure the distance. |
Returns
Type | Description |
---|---|
System.Double |
Overrides
PointAt(Double)
Get a point along the line at parameter u.
Declaration
public override Vector3 PointAt(double u)
Parameters
Type | Name | Description |
---|---|---|
System.Double | u | A parameter on the curve between 0.0 and length. |
Returns
Type | Description |
---|---|
Vector3 | A point on the curve at parameter u. |
Overrides
PointOnLine(Vector3, Vector3, Vector3, Boolean, Double)
Test if a point lies within tolerance of a given line segment.
Declaration
public static bool PointOnLine(Vector3 point, Vector3 start, Vector3 end, bool includeEnds = false, double tolerance = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | point | The point to test. |
Vector3 | start | The start point of the line segment. |
Vector3 | end | The end point of the line segment. |
System.Boolean | includeEnds | Consider a point at the endpoint as on the line. |
System.Double | tolerance | An optional distance tolerance. When true, any point within tolerance of the end points will be considered on the line. When false, points precisely at the ends of the line will not be considered on the line. |
Returns
Type | Description |
---|---|
System.Boolean |
PointOnLine(Vector3, Boolean, Double)
Test if a point lies within tolerance of this line segment.
Declaration
public bool PointOnLine(Vector3 point, bool includeEnds = false, double tolerance = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | point | The point to test. |
System.Boolean | includeEnds | Consider a point at the endpoint as on the line. |
System.Double | tolerance | An optional distance tolerance. When true, any point within tolerance of the end points will be considered on the line. When false, points precisely at the ends of the line will not be considered on the line. |
Returns
Type | Description |
---|---|
System.Boolean |
Projected(Plane)
Projects current line onto a plane
Declaration
public Line Projected(Plane plane)
Parameters
Type | Name | Description |
---|---|---|
Plane | plane | Plane to project |
Returns
Type | Description |
---|---|
Line | New line on a plane |
Reversed()
Get a new line that is the reverse of the original line.
Declaration
public Line Reversed()
Returns
Type | Description |
---|---|
Line |
Thicken(Double)
Thicken a line by the specified amount.
Declaration
public Polygon Thicken(double amount)
Parameters
Type | Name | Description |
---|---|---|
System.Double | amount | The amount to thicken the line. |
Returns
Type | Description |
---|---|
Polygon |
ToString()
A string representation of the line.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Overrides
TransformAt(Double)
Get a transform whose XY plane is perpendicular to the curve, and whose positive Z axis points along the curve.
Declaration
public override Transform TransformAt(double u)
Parameters
Type | Name | Description |
---|---|---|
System.Double | u | The parameter along the Line, between 0.0 and 1.0, at which to calculate the Transform. |
Returns
Type | Description |
---|---|
Transform | A transform. |
Overrides
Transformed(Transform)
Create a transformed copy of this curve. Use of non-affine transforms (i.e. scale) will result in unpredictable results for curve methods such as Length().
Declaration
public override Curve Transformed(Transform transform)
Parameters
Type | Name | Description |
---|---|---|
Transform | transform | The transform to apply. |
Returns
Type | Description |
---|---|
Curve |
Overrides
TransformedLine(Transform)
Construct a transformed copy of this Line.
Declaration
public Line TransformedLine(Transform transform)
Parameters
Type | Name | Description |
---|---|---|
Transform | transform | The transform to apply. |
Returns
Type | Description |
---|---|
Line |
Trim(Polygon, out List<Line>, Boolean, Boolean)
Trim a line with a polygon.
Declaration
public List<Line> Trim(Polygon polygon, out List<Line> outsideSegments, bool includeCoincidenceAtEdge = false, bool infinite = false)
Parameters
Type | Name | Description |
---|---|---|
Polygon | polygon | The polygon to trim with. |
System.Collections.Generic.List<Line> | outsideSegments | A list of the segment(s) of the line outside of the supplied polygon. |
System.Boolean | includeCoincidenceAtEdge | Include coincidence at edge as inner segment. |
System.Boolean | infinite | Treat the line as infinite? |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<Line> | A list of the segment(s) of the line within the supplied polygon. |
TrimTo(Line, Boolean)
Trim this line to the trimming curve.
Declaration
public Line TrimTo(Line line, bool flip = false)
Parameters
Type | Name | Description |
---|---|---|
Line | line | The curve to which to trim. |
System.Boolean | flip | Should the trim direction be reversed? |
Returns
Type | Description |
---|---|
Line | A new line, or null if this line does not intersect the trimming line. |
TryGetOverlap(Line, out Line)
Check if this line overlaps with another line.
Declaration
public bool TryGetOverlap(Line line, out Line overlap)
Parameters
Type | Name | Description |
---|---|---|
Line | line | Line to check. |
Line | overlap | Overlapping line or null when lines do not overlap. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true when lines overlap and false when they do not. |
TryGetOverlap(Line, Double, out Line)
Check if this line overlaps with another line.
Declaration
public bool TryGetOverlap(Line line, double tolerance, out Line overlap)
Parameters
Type | Name | Description |
---|---|---|
Line | line | Line to check |
System.Double | tolerance | Tolerance for distance-based checks. |
Line | overlap | Overlapping line or null when lines do not overlap. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true when lines overlap and false when they do not. |