rotate_v2v: Rotate vector onto vector

View source: R/geom_rotate.R

rotate_v2vR Documentation

Rotate vector onto vector

Description

Determines rotation needed to align the first input vector (l1) with the second input vector (l2), and applies it to the input 3D data. If the second vector is on an axis (e.g. two different X values, and y,z = 0 at both endpoints), then this will simply align the 3D data with that axis.

Usage

rotate_v2v(l1, l2, coords)

Arguments

l1

A 2x3 matrix-like object containing endpoint coordinates of a vector defining object axis, one per row. If more than two coordinates given, only the first two will be used.

l2

A 2x3 matrix-like object containing endpoint coordinates of reference vector to be rotated onto, one per row. If more than two coordinates given, only the first two will be used.

coords

An Nx3 matrix-like object containing coordinates to be rotated, one per row.

Value

A list containing a rotated coordinates matrices for the data (coords) and first input vector (l)

Examples

# Simple example
l1 = data.frame(x=c(0,1), y=c(0,1), z=c(0,1))
l2 = data.frame(x=c(0,1), y=c(0,0), z=c(0,0))
coords = data.frame(x=c(1,2), y=c(1,2), z=c(1,2))
res = rotate_v2v(l1, l2, coords)
# Example applied to a mesh:
library(rgl)
data(demoFlake2)
view3d(theta=0, phi=0)
axes3d()
shade3d(demoFlake2$mesh, color="green")
points3d(demoFlake2$lms[c(3,8),], color="red", size=10)
al.res <- rotate_v2v(l1=demoFlake2$lms[c(3, 8), 1:3],
                    l2=data.frame(x=c(0,1), y=c(0,0), z=c(0,0)),
                    t(demoFlake2$mesh$vb)[, 1:3])
m.rot <- list(vb=t(cbind(al.res$coords, 1)), it=demoFlake2$mesh$it)    
class(m.rot) <- "mesh3d"
shade3d(m.rot, color="blue")
points3d(al.res$l, color="purple", size=10)

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