proj_pt2l | R Documentation |
Projects given coordinates onto a line.
proj_pt2l(coords, l)
coords |
A Nx3 matrix-like object with coordinates defining a line, one per row. |
l |
A 2x3 matrix-like object with coordinates defining a line, one per row. |
Cleanup and test!
Formula from https://gamedev.stackexchange.com/questions/72528/how-can-i-project-a-3d-point-onto-a-3d-line
Cornel M. Pop
library(rgl)
coords = data.frame(x=13.70658, y=-92.22888, z=7.983234)
l = data.frame(x=c(14.19899, -13.26872), y=c(-81.14718, -75.11636),
z=c(10.4734, -27.9210))
pt = proj_pt2l(coords, l)
points3d(l, color="red")
points3d(rbind(coords, coords), color="blue")
points3d(rbind(pt, pt), color="green")
lines3d(l, color="red")
lines3d(rbind(as.matrix(coords), pt), color="green")
dist(rbind(as.matrix(coords), pt), method="euclidean") # Verify that correct.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.