C++ 确定将一个平面转换为平行平面的仿射变换
如何确定CGAL仿射变换(Aff_变换_3),该变换将一个平面(plane1)转换为一个平行于另一个平面(plane2)的平面 假设我有两个对象平面:C++ 确定将一个平面转换为平行平面的仿射变换,c++,cgal,affinetransform,C++,Cgal,Affinetransform,如何确定CGAL仿射变换(Aff_变换_3),该变换将一个平面(plane1)转换为一个平行于另一个平面(plane2)的平面 假设我有两个对象平面: Plane_3 pl1; Plane_3 pl2; 它们不是平行的,如何确定这种仿射变换 Aff_transformation_3 t3 = ??? (pl1, pl2); 我参考了这个问题和你的答案,但我不知道这对我有什么帮助。我有两个平面,但都是三维的 谢谢。我不知道2d仿射变换(Aff_变换_2)如何帮助我应用3d仿射变换(Aff_
Plane_3 pl1;
Plane_3 pl2;
它们不是平行的,如何确定这种仿射变换
Aff_transformation_3 t3 = ??? (pl1, pl2);
我参考了这个问题和你的答案,但我不知道这对我有什么帮助。我有两个平面,但都是三维的
谢谢。我不知道2d仿射变换(Aff_变换_2)如何帮助我应用3d仿射变换(Aff_变换_3) 然而,我找到了问题的答案。这是我希望能帮助别人的may位代码
typedef CGAL::Cartesian<double> KC;
typedef KC::Line_3 Line3;
typedef KC::Vector_3 Vector3;
typedef KC::Plane_3 Plane3;
typedef CGAL::Aff_transformation_3<KC> Transform3;
// forwards
struct axis_angle;
typedef boost::shared_ptr<axis_angle> RAxisAngle;
struct axis_angle
{
axis_angle()
{
angle = 0;
axis = Vector3(0.0, 0.0, 0.0);
}
double angle;
Vector3 axis;
};
Vector3 normalize(const Vector3 &v)
{
ldouble len = ::sqrt(v.squared_length());
if (len == 0.0)
return v;
return v / len;
}
// return the angle and axis from two planes that there are not parallels
RAxisAngle axis_angle_from_planes(const Plane3 &pln1, const Plane3 &pln2)
{
RAxisAngle result = RAxisAngle(new axis_angle());
Vector3 norm1 = pln1.orthogonal_vector();
Vector3 norm2 = pln2.orthogonal_vector();
double dot_r = norm1 * norm2;
double len_r = ::sqrt(norm1.squared_length() * norm2.squared_length());
if (len_r)
result->angle = ::acos(dot_r / len_r);
else
result->angle = 0.0;
Line3 l1;
CGAL::Object obj_cgal = CGAL::intersection(pln1, pln2);
if (CGAL::assign(l1, obj_cgal))
{
result->axis = normalize(l1.to_vector());
}
else
{
// when planes are parallels, then use some basic axis
result->axis = Vector3(1.0, 0.0, 0.0);
}
return result;
}
// return a CGAL affine transformation that is builded from a 3x3 matrix
// this transformation is for rotate an object from axis and angle
// http://en.wikipedia.org/wiki/Transformation_matrix
// http://en.wikipedia.org/wiki/Rotation_matrix
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToMatrix/index.htm
Transform3 axis_angle_to_matrix(const RAxisAngle &aa)
{
double tmp1, tmp2;
double c = ::cos(aa->angle);
double s = ::sin(aa->angle);
double t = 1.0 - c;
double m00 = c + aa->axis.x() * aa->axis.x() * t;
double m11 = c + aa->axis.y() * aa->axis.y() * t;
double m22 = c + aa->axis.z() * aa->axis.z() * t;
tmp1 = aa->axis.x() * aa->axis.y() * t;
tmp2 = aa->axis.z() * s;
double m10 = tmp1 + tmp2;
double m01 = tmp1 - tmp2;
tmp1 = aa->axis.x() * aa->axis.z() * t;
tmp2 = aa->axis.y() * s;
double m20 = tmp1 - tmp2;
double m02 = tmp1 + tmp2;
tmp1 = aa->axis.y() * aa->axis.z() * t;
tmp2 = aa->axis.x() * s;
double m21 = tmp1 + tmp2;
double m12 = tmp1 - tmp2;
return Transform3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
}
或者这个平面的一个点:
Point3 new_transform_point = point_of_plane1.transform(t3);
谢谢你让我有机会发布我的小解决方案。这是实用的代码问题还是理论问题?这也是一个代码问题。我找到了一个奇怪的解决方案,解决了我的问题。由于答案已禁用,我如何发布它?我已请求重新打开该问题。@GilbertoCuba您现在可以发布您的自我答案了吗?问题似乎重新开始了。谢谢你分享你的解决方案,吉尔伯托。我对你的答案投了赞成票。
Point3 new_transform_point = point_of_plane1.transform(t3);