mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-10-04 05:56:31 +08:00
finishing rotation vec to vec function
This commit is contained in:
parent
293a6bfe10
commit
9b3d8a1156
@ -323,6 +323,8 @@ TransformationMatrix TransformationMatrix::mat_rotation(double angle_rad, const
|
|||||||
|
|
||||||
TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3 target)
|
TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3 target)
|
||||||
{
|
{
|
||||||
|
// TODO: there is a lot of float <-> double conversion going on here
|
||||||
|
|
||||||
TransformationMatrix mat;
|
TransformationMatrix mat;
|
||||||
double length_sq = origin.x*origin.x + origin.y*origin.y + origin.z*origin.z;
|
double length_sq = origin.x*origin.x + origin.y*origin.y + origin.z*origin.z;
|
||||||
double rec_length;
|
double rec_length;
|
||||||
@ -349,8 +351,8 @@ TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3
|
|||||||
cross.z = origin.x*target.y - origin.y*target.x;
|
cross.z = origin.x*target.y - origin.y*target.x;
|
||||||
|
|
||||||
length_sq = cross.x*cross.x + cross.y*cross.y + cross.z*cross.z;
|
length_sq = cross.x*cross.x + cross.y*cross.y + cross.z*cross.z;
|
||||||
if (length_sq < 1e-12) {// colinear, but maybe opposite directions
|
|
||||||
double dot = origin.x*target.x + origin.y*target.y + origin.z*target.z;
|
double dot = origin.x*target.x + origin.y*target.y + origin.z*target.z;
|
||||||
|
if (length_sq < 1e-12) {// colinear, but maybe opposite directions
|
||||||
if (dot > 0.0)
|
if (dot > 0.0)
|
||||||
{
|
{
|
||||||
return mat; // same direction, nothing to do
|
return mat; // same direction, nothing to do
|
||||||
@ -368,15 +370,21 @@ TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3
|
|||||||
// projection of axis onto unit vector origin
|
// projection of axis onto unit vector origin
|
||||||
dot = origin.x*help.x + origin.y*help.y + origin.z*help.z;
|
dot = origin.x*help.x + origin.y*help.y + origin.z*help.z;
|
||||||
proj.scale(dot);
|
proj.scale(dot);
|
||||||
|
|
||||||
// help - proj is normal to origin -> rotation axis
|
// help - proj is normal to origin -> rotation axis
|
||||||
// axis is not unit length -> gets normalized in called function
|
|
||||||
Pointf3 axis = (Pointf3)proj.vector_to(help);
|
Pointf3 axis = (Pointf3)proj.vector_to(help);
|
||||||
|
|
||||||
|
// axis is not unit length -> gets normalized in called function
|
||||||
return mat_rotation(PI, axis);
|
return mat_rotation(PI, axis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{// not colinear, cross represents rotation axis so that angle is positive
|
||||||
|
// dot's vectors have previously been normalized, so nothing to do except arccos
|
||||||
|
double angle = acos(dot);
|
||||||
|
|
||||||
|
// cross is (probably) not unit length -> gets normalized in called function
|
||||||
|
return mat_rotation(angle, cross);
|
||||||
}
|
}
|
||||||
return mat; // Shouldn't be reached
|
return mat; // Shouldn't be reached
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user