I am using the rgl package to create 3D plots of my data. For some reasons (3D PCA biplots) I need vectors -- a line segment with an arrow. And I'm stuck, because I want to have 3D cones as arrow heads.
Somehow, I cannot wrap my senile mind around the geometry of the problem. Say, I would draw the vector with
segments3d( rbind( c( 0, 0, 0 ), c( 3, 3, 3 ) ) )
that is, a vector from the origin of the user coordinate system to [3,3,3].
I would like to create a cone with the tip at [3,3,3]. The base of the cone can be formed with a circle. Drawing a circle on the xz plane (perpendicular to the y plane) with radius r is easy:
n <- 10
sin.t <- sin( seq( 0, 2 * pi, len= n ) )
cos.t <- cos( seq( 0, 2 * pi, len= n ) )
r <- 0.1
xv <- x + r * sin.t
yv <- rep( y, n )
zv <- z + r * cos.t
but how do I now transform these points such that the circle is now perpendicular to the vector? And its center 0.2 from the tip along the vectors direction? Once I have this transformation, I will draw triangles with the triangles3d function, each triangle having one corner at the tip and two vertices within the points of the circle.
This is basic maths, and I know the 18 year old me would not have a problem (or even a 28 year old me). Any hook (as opposed to fish) would be appreciated.