Transformation Matrix (4 x 4) in lidR - Issue during export #782
Unanswered
BastienUlg
asked this question in
Q&A
Replies: 1 comment
-
Try not to use
Before to modify the point cloud, modify the header such as your # Function to apply a 4x4 transformation matrix to the point cloud
apply_transformation <- function(las, transformation_matrix)
{
# Extract point coordinates (X, Y, Z) and add a column of 1s for affine transformation
coords <- cbind(las@data$X, las@data$Y, las@data$Z, rep(1, nrow(las@data)))
# Apply the transformation matrix (matrix multiplication)
transformed_coords <- coords %*% t(transformation_matrix)
# Update the LAS object with transformed coordinates
Xt <- transformed_coords[, 1]
Yt <- transformed_coords[, 2]
Zt <- transformed_coords[, 3]
xoffset = floor(min(Xt))
yoffset = floor(min(Yt))
zoffset = floor(min(Zt))
las@header$`X offset` = xoffset
las@header$`Y offset` = yoffset
las@header$`Z offset` = zoffset
# Update the LAS object with transformed coordinates
las$X <- transformed_coords[, 1]
las$Y <- transformed_coords[, 2]
las$Z <- transformed_coords[, 3]
return(las)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use a transformation matrix like the one implemented in Cloud Compare.
When I'm applying the matrix, the X,Y and Z coordinates look fine. Yet when I'm exporting the laz point cloud using the WriteLas function, I observe a significant offset in the exported point cloud (i.e., the coordinates are different than the one I had in R - see the two pictures in attachment).
I first thought that it was a shift caused by the coordinate system but this is not the source of the issue.
![Capture d’écran 2024-09-26 112124](https://private-user-images.githubusercontent.com/124399228/371289746-9c086a8b-aa11-4245-8ca8-54818ecb5481.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0Mjk2MTIsIm5iZiI6MTczOTQyOTMxMiwicGF0aCI6Ii8xMjQzOTkyMjgvMzcxMjg5NzQ2LTljMDg2YThiLWFhMTEtNDI0NS04Y2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NWE5MTRlMWU4MWNlNzA3YTg3MTJhZDAxNDAxNmE2M2Q3OWYxYjdiMTQ2JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.UUH5uhcs81zCVwo9kFUlMR3wd67ClU5goR7-ZESHl-Y)
Maybe it's related to the large number od decimal
value in the transformation matrix?
Potentially a header issue?
Any idea how to resolve this issue? Thanks a lot!
Here is the code with a small subset of the las file available on Gdrive:
https://drive.google.com/drive/folders/1gtf8jQjw82jWm7MjnDD97KNbL9KbH9fP?usp=sharing
Beta Was this translation helpful? Give feedback.
All reactions