pointOnLine {matlib} | R Documentation |
Position of a point along a line
Description
A utility function for drawing vector diagrams. Find position of an interpolated point along a line from x1
to x2
.
Usage
pointOnLine(x1, x2, d, absolute = TRUE)
Arguments
x1 |
A vector of length 2 or 3, representing the starting point of a line in 2D or 3D space |
x2 |
A vector of length 2 or 3, representing the ending point of a line in 2D or 3D space |
d |
The distance along the line from |
absolute |
logical; if |
Details
The function takes a step of length d
along the line defined by the difference between the two points, x2 - x1
.
When absolute=FALSE
, this step is proportional to the difference,
while when absolute=TRUE
, the difference is first scaled to unit length so that the step is always of length d
.
Note that the physical length of a line in different directions in a graph depends on the aspect ratio of the plot axes,
and lines of the same length will only appear equal if the aspect ratio is one
(asp=1
in 2D, or aspect3d("iso")
in 3D).
Value
The interpolated point, a vector of the same length as x1
See Also
Other vector diagrams:
Proj()
,
arc()
,
arrows3d()
,
circle3d()
,
corner()
,
plot.regvec3d()
,
regvec3d()
,
vectors()
,
vectors3d()
Examples
x1 <- c(0, 0)
x2 <- c(1, 4)
pointOnLine(x1, x2, 0.5)
pointOnLine(x1, x2, 0.5, absolute=FALSE)
pointOnLine(x1, x2, 1.1)
y1 <- c(1, 2, 3)
y2 <- c(3, 2, 1)
pointOnLine(y1, y2, 0.5)
pointOnLine(y1, y2, 0.5, absolute=FALSE)