Rotating a quad to xy plane

function [p,M,v] = flatten_polygon(v)
% v: 4×3 [x1 y1 z1; x2 y2 z2; x3 y3 z3; x4 y4 z4] or 3×3
% p: 4×2 [0 0; X2 Y2; X3 Y3; X4 Y4] or 3×2

% idea:
% move v1 to (0,0,0)
% compute the unit normal (right hand)
% rotate it to (0,0,1)

%% shift first poin…


This content originally appeared on DEV Community and was authored by Lingjun Jiang

function [p,M,v] = flatten_polygon(v)
% v: 4x3 [x1 y1 z1; x2 y2 z2; x3 y3 z3; x4 y4 z4] or 3x3
% p: 4x2 [0 0; X2 Y2; X3 Y3; X4 Y4] or 3x2

% idea: 
% move v1 to (0,0,0)
% compute the unit normal (right hand)
% rotate it to (0,0,1)

%% shift first point to origin
v = [v(:,1) - v(1,1), v(:,2) - v(1,2), v(:,3) - v(1,3)];

%% compute unit normal

N = cross(v(2,:), v(3,:));
N = N ./ norm(N);

%% rotate about an axis
deg = acos(N(:,3))*180/pi;
u = cross(N, [0 0 1]);
M = AxelRot(deg,u);
M = M(1:3,1:3);

p = (M*v')';
p(:,3) = [];

end

The core of this function lies in the rotation AxelRot()!


This content originally appeared on DEV Community and was authored by Lingjun Jiang


Print Share Comment Cite Upload Translate Updates
APA

Lingjun Jiang | Sciencx (2024-09-03T02:01:52+00:00) Rotating a quad to xy plane. Retrieved from https://www.scien.cx/2024/09/03/rotating-a-quad-to-xy-plane/

MLA
" » Rotating a quad to xy plane." Lingjun Jiang | Sciencx - Tuesday September 3, 2024, https://www.scien.cx/2024/09/03/rotating-a-quad-to-xy-plane/
HARVARD
Lingjun Jiang | Sciencx Tuesday September 3, 2024 » Rotating a quad to xy plane., viewed ,<https://www.scien.cx/2024/09/03/rotating-a-quad-to-xy-plane/>
VANCOUVER
Lingjun Jiang | Sciencx - » Rotating a quad to xy plane. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/03/rotating-a-quad-to-xy-plane/
CHICAGO
" » Rotating a quad to xy plane." Lingjun Jiang | Sciencx - Accessed . https://www.scien.cx/2024/09/03/rotating-a-quad-to-xy-plane/
IEEE
" » Rotating a quad to xy plane." Lingjun Jiang | Sciencx [Online]. Available: https://www.scien.cx/2024/09/03/rotating-a-quad-to-xy-plane/. [Accessed: ]
rf:citation
» Rotating a quad to xy plane | Lingjun Jiang | Sciencx | https://www.scien.cx/2024/09/03/rotating-a-quad-to-xy-plane/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.