diff --git a/change.txt b/change.txt index 0cb33f28..66fa0060 100644 --- a/change.txt +++ b/change.txt @@ -1,5 +1,12 @@ YEAR-MONTH-DAY +--------------------------------------------- +Date : 2023-XXX-X +Version : 0.26.2 + +- LineSegment2D + * Added pointOnLine functions + --------------------------------------------- Date : 2023-May-15 Version : 0.26.1 diff --git a/main/src/georegression/struct/line/LineSegment2D_F64.java b/main/src/georegression/struct/line/LineSegment2D_F64.java index c6ccd7e7..11703d0e 100644 --- a/main/src/georegression/struct/line/LineSegment2D_F64.java +++ b/main/src/georegression/struct/line/LineSegment2D_F64.java @@ -21,6 +21,7 @@ import georegression.struct.point.Point2D_F64; import lombok.Getter; import lombok.Setter; +import org.jetbrains.annotations.Nullable; import java.io.Serializable; @@ -75,6 +76,31 @@ public void zero() { b.zero(); } + /** + * Computes a point on the line based on the fraction distance between 'a' and 'b' + */ + public Point2D_F64 pointOnLine( double fraction, @Nullable Point2D_F64 p ) { + if (p == null) + p = new Point2D_F64(); + p.x = axisOnLineX(fraction); + p.y = axisOnLineY(fraction); + return p; + } + + /** + * Value of x-axis for a point on the line at this fractional location between 'a' and 'b' + */ + public double axisOnLineX( double fraction ) { + return slopeX()*fraction + a.x; + } + + /** + * Value of y-axis for a point on the line at this fractional location between 'a' and 'b' + */ + public double axisOnLineY( double fraction ) { + return slopeY()*fraction + a.y; + } + public double slopeX() { return b.x - a.x; }