proj_pt2l: Orthogonally project points onto a line

View source: R/geom_dist.R

proj_pt2lR Documentation

Orthogonally project points onto a line

Description

Projects given coordinates onto a line.

Usage

proj_pt2l(coords, l)

Arguments

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.

TODO

Cleanup and test!

Note

Formula from https://gamedev.stackexchange.com/questions/72528/how-can-i-project-a-3d-point-onto-a-3d-line

Author(s)

Cornel M. Pop

Examples

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.

cornelmpop/Lithics3D documentation built on Feb. 10, 2024, 11:54 p.m.