I'm working on my master thesis to simulate hemispherical photographs from Lidar-Data. So my main goal is to project 3D Points (X,Y,Z) which are in a cartesian coordinate system to a stereographic projection (See picture 1, from: here). The coordinate-system of my Pointcloud is transformed so that the center point is located a (0,0,0) and all z-values are positive.
I'm coding in RStudio and I first tried to achieve a spherical projection of the Pointcloud by using the formula for cartesian to spherical coordinates listed on wikipedia.
r <- sqrt(x^2 + y^2 + z^2)
theta <- acos(z/r)
phi <- atan2(y,x)
I also tried to do it with the cart2sph-function from the RPackage pracma which should do the same. But unfortunately the results with both methods don't look nearly how I wanted them to be. The points don't fit on a plane half-sphere but just seem to be oriented along the z-axis (See picture 2).
Has anyone suggestions how to achieve the stereographic projection of the Lidar Pointcloud in RStudio? Is there maybe even a package with some functions to do a coordinate transformation? Unfortunately I don't have many coding experiences, I would be very thankful for every help.
Edit
I plot the cartesian points on a hemisphere using Allans script. The result looks like this using the software Cloudcompare:
Image: Hemisphere
I also did a stereographic projection with the transformed cartesian coordinates:
x2 <- (x / (1 + z))
y2 <- (y / (1 + z))
project_2d <- data.frame(x2, y2)
Image: Stereographic projection
Still I wonder why the outer edge of the plots don't fit a perfect circle since all tree trunks have the same min(z) value (I used a clipping box). So all tree trunks should line up on the "equator" of the hemisphere. Do you have any clue?