transfer function of a geometry to match another identical geometry
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hamid
le 7 Sep 2018
Réponse apportée : Hamid
le 12 Sep 2018
I have 2 identical 3D spatial geometry (in a CAD software). I want to find a transfer function (sequences of transforms and rotations around x, y and z axes) to move one to merge and match the other one. Is there any code or program that takes the coordinate of several points from both source and destination geometries and calculate the required moves and rotations?
0 commentaires
Réponse acceptée
David Goodmanson
le 9 Sep 2018
Hi Hamid,
Do you need the actual sequence of rotations around the x,y, and z axes, or do you just need a 3x3 matrix that gets the job done regardless of the actual sequence? If it is the latter, then here is a method.
Assume you have a set of N points p_full in the form of an Nx3 matrix, where the x,y,z coordinates read across and each row represents one point. Assume the same for another set of M points in q_full. p_full and q_full must have at least three points in common or you can't get anywhere. So let p and q each be nx3 matrices for n points in common between p_full and q_full, with the points in the same order for p and q. n has to be at least 3, and more is better if there is some slight inaccuracy in the coordinates. The following code transforms q to qnew, which falls on top of p.
% make up some data
p = rand(12,3) + [1 4 3];
S = [orth([2 1 5]'),null([2 1 5])];
q = (p-mean(p))*S + [3 0 6];
% -----------------------
% find the rotation and translation from that data
pcm = mean(p);
qcm = mean(q);
R = (q-qcm)\(p-pcm);
R*R' % check that R is an orthogonal transformation, 3x3 identity
qnew = (q-qcm)*R + pcm; % qnew should fall on top of points p
figure(1)
scatter3(p(:,1),p(:,2),p(:,3),'k')
hold on
scatter3(q(:,1),q(:,2),q(:,3),'r')
hold on
scatter3(qnew(:,1),qnew(:,2),qnew(:,3),'b')
hold off
The new blue qnew points fall on top of the old black p points so you can't see them. If you have extra points in q_full that don't correspond to anything in p, the same transformation
qnew_full = (q_full-qcm)*R + pcm;
gives all the transformed points.
2 commentaires
David Goodmanson
le 10 Sep 2018
Modifié(e) : David Goodmanson
le 10 Sep 2018
Yes, it's good to use as many matching points as possible (assuming no points are seriously off for some reason). Matlab solves for R by minimizing the least squares error which is probably the best you can do.
I'm not sure what your first sentence means exactly. Adding the vector to each row of the matrix was what was supposed to happen.
Does the CAD software use fixed-in-space axes and rotate the model (active transformation)? Can you stretch or shrink the model along the individual axes? R can be decomposed reasonably accurately into a product such as Rz*Rx*Rz, and basically exactly if the size change along the axes is allowed.
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur 3-D Scene Control dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!