Skip to content

Commit

Permalink
LineSegment2D_F64
Browse files Browse the repository at this point in the history
- Added pointOnLine and related
  • Loading branch information
lessthanoptimal committed May 30, 2023
1 parent 78a3bde commit a344a69
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions change.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 26 additions & 0 deletions main/src/georegression/struct/line/LineSegment2D_F64.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit a344a69

Please sign in to comment.