Reputation: 169
I have 3D meshes representing closed surfaces not necessarily convex for which I would like to get orthographic projections onto arbitrary directions (to put in context, the 3D meshes represent satellites and the end goal is to use the projections to calculate atmospheric drag).
As a first step, I am just aiming to compute the surface area of the resulting projection. Is there any way to perform such operation with rgl? Since the meshes represent closed surfaces, the projections will not contain multiple disconnected polygons.
I believe I can get the set of triangles/quads visible from a given direction by using the facing3d()
function, specifying the direction in the up
argument. But I am unsure on how to proceed from there.
Upvotes: 0
Views: 253
Reputation: 44867
You can do the projections using the rgl::shadow3d()
function, and calculate area using geometry::polyarea()
. For example,
library(rgl)
library(geometry)
satellite <- translate3d(icosahedron3d(), x = 0, y = 0, z = 5)
vertices <- asEuclidean2(satellite$vb)
xrange <- range(vertices[1,])
yrange <- range(vertices[2,])
floor <- mesh3d(x = c(2*xrange, 2*rev(xrange)),
y = rep(2*yrange, each = 2),
z = 0, quads = 1:4)
open3d()
#> glX
#> 1
shadow <- shadow3d(floor, satellite, plot = FALSE,
minVertices=1000 # Need this to get a good shadow
)
shade3d(satellite, col= "red")
shade3d(floor, col = "white", polygon_offset = 1, alpha = 0.1)
shade3d(shadow, col = "gray")
vertices <- unique(t(asEuclidean2(shadow$vb)))[,1:2]
hull <- chull(vertices)
hullx <- vertices[hull,1]
hully <- vertices[hull,2]
plot(c(hullx, hullx[1]), c(hully, hully[1]), type = "l")
polyarea(hullx, hully)
#> [1] 3.266855
Created on 2022-12-13 with reprex v2.0.2
Upvotes: 1