老师好,我想问下,在元素旋转和平移的过程中,如果我先将元素平移某个线得端点,然后再该线端点处求切向量/法向量 构造旋转矩阵,然后进行变换,这个思路有问题?还是牵涉到旋转得时候必须要先将元素移动到世界坐标系原点处呢?
您的思路没问题,下面代码是我之前项目的一部分,是C++的,根据一条路径和一个截面,将截面移动到路径的起点上,跟路径垂直,然后拉伸的一个体:
StatusInt PSSubgradePlaceLoftSolidTool::SolidByExtrudeAlong(CurveVectorPtr& curve, CurveVectorPtr& path) { DPoint3d stPt, endPt; DVec3d stVec, endVec; path->GetStartEnd(stPt, endPt, stVec, endVec); DVec3d xVec, yVec, zVec; RotMatrix rMatrix; xVec = stVec; zVec.Init(0.0, 0.0, 1.0); yVec = DVec3d::FromCrossProduct(zVec, xVec); yVec.Normalize(); zVec = DVec3d::FromCrossProduct(xVec, yVec); zVec.Normalize(); rMatrix = RotMatrix::FromColumnVectors(yVec, zVec, xVec); Transform vecTransform = Transform::From(rMatrix, stPt); curve->TransformInPlace(vecTransform); ISolidKernelEntityPtr body; BentleyStatus status; if (SUCCESS != SolidUtil::Create::BodyFromSweep(body, *curve.get(), *path.get(), *ACTIVEMODEL, false, true, false)) { return false; } if (body == nullptr) return false; EditElementHandle sweepEh; BentleyStatus nStatus = SolidUtil::Convert::BodyToElement(sweepEh, *body.get(), nullptr, *ACTIVEMODEL); if (BentleyStatus::SUCCESS == nStatus) { sweepEh.AddToModel(); } return SUCCESS; }
张工,看了上述你得代码,我知道我的问题出现再哪里啦,我直接将Z向量,直接使用了 DVector3d zVec = new DVector3d(); zVec.X = 0; zVec.Y = 0; zVec.Z = 1;没有再叉乘求。还有一个问题 就是构造 rMatrix = RotMatrix::FromColumnVectors(yVec, zVec, xVec);旋转矩阵得时候,为什么xVec, yVec, zVec没有按照顺序传入呢?而是按照(yVec, zVec, xVec)这个顺序传入得呢?
这个是根据你想旋转成什么样决定的,就这三个参数,您按照右手系去一个个试一下就知道了。
Answer Verified By: Duo Duo