找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 945|回复: 4

[求助] 求助,关于三维实体的平移和旋转

[复制链接]
发表于 2017-2-28 16:49:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
如何根据一直线的两个端点(X,Y,Z都有值)在建模后平移和旋转到相应的位置和方向。建模问题不大,关键是如何进行平移和旋转。最好能提供一下实例,无尽感激!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 859个

财富等级: 财运亨通

发表于 2017-2-28 17:01:37 | 显示全部楼层
用矩阵转换
public void TransformBy(
    Matrix3d transform
);
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-28 17:16:20 | 显示全部楼层
我也是知道用矩阵转换,主要是搞不清三个轴的转换角度
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 20个

财富等级: 恭喜发财

发表于 2017-2-28 17:41:08 | 显示全部楼层

角度已知就 setRotation
未知,你就用alignCoordsys 对齐坐标轴计算出变换矩阵
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2017-2-28 17:59:30 | 显示全部楼层

下面文章是将关于矩阵的,你参考下

Question
How do I build a transformation matrix to be used to manipulate entities when I
have only a position, normal vector, scale and rotation?
Answer
You may use AcGeMatrix3d members to create your transformation matrix directly.
First, given the normal (Z Axis), you must construct the remaining axes (X and
Y). AutoCAD can construct one of them (X) for you using the perpVector() method
(perpVector() generates a perpendicular vector based upon the 'Arbitrary Axis
Algorithm'). The third axis (Y) can be created by calculating the cross-product
between the X and Z axes. Since you plan on rotating your entities, you may
need to know how this arbitrary axis is calculated. Here is a pseudocode breakdown.

(Vec is the argument passed to perpVector())

If abs(X and Y) of Vec(X,Y,Z) are both < .015625 (1/64), then
newVec.X=Vec.Z
newVec.Y=0.0
newVec.Z=-Vec.X
Otherwise
newVec.X=Vec.Y
newVec.Y=Vec.X
newVec.Z=0.0

(Note: either of these result axes are perpendicular to Vec.)

Once the X, Y, Z axes have been defined, you can use the setCoordSystem() method
of AcGeMatrix3d. setCoordSystem takes an origin PT, and the X,Y,Z vectors as
arguments to create a composite transformation matrix that, when applied, can
perform both rotation and translation on entities or geometry. Rotation and
scaling can be accomplished by creating matrices and applying them (multiplying)
to the coordinate system matrix you have just defined. Use the setToRotation()
and setToScaling() member functions of AcGeMatrix3d to create them, and once
created, you just multiply them with the coordinate system matrix. Remember
that matrix multiplication is not always commutative so care is needed in the
multiplication order.

Example: (no error checking...)


AcGeVector3d xAxis=normal.perpVector(); // Get a perpendicular vector
(Arbitrary Axis Algorithm) for the X Axis
AcGeVector3d yAxis=zAxis.crossProduct(xAxis); // get the Y Axis

AcGeMatrix3d rotMat,scaleMat,transMat,coordSysMat;

rotMat.setToRotation(rotation,normal); // Create a rotation matrix
scaleMat=scale.operator AcGeMatrix3d();// Create a scale matrix from your AcGeScale object
transMat.setToTranslation(asVec3d(asDblArray(position)));// Create a
translation matrix

coordSysMat.setCoordSystem(AcGePoint3d::kOrigin,
xAxis, yAxis, normal); // Create a coordinate system matrix based upon your axes
coordSysMat = scaleMat * mat; // Scale the matrix...note the multiplication order
coordSysMat = rotMat * coordSysMat; // Rotate the matrix, again note the multiplication order
coordSysMat = transMat * coordSysMat; // Translate the matrix, this has to be last.


I have shown the above method as a means for demonstrating some techniques for
matrix manipulation in AutoCAD. However, an alternate approach, since you know
the rotation angle, would be to rotate the vectors before you create the coordSys
matrix. This way, you reduce the number of matrix multiplications, thereby speeding
up your code.

Example:


AcGeMatrix3d coordSysMat;

AcGeVector3d xAxis=normal.perpVector(); // Get a perpendicular vector
(Arbitrary Axis Algorithm) for the X Axis
AcGeVector3d yAxis=zAxis.crossProduct(xAxis); // get the Y Axis
xAxis.rotateBy(rotation,normal);
yAxis.rotateBy(rotation,normal);
coordSysMat.setCoordSystem(position,xAxis,yAxis,normal); // create the
composite matrix.
// Notice the 'position' value can be used instead of 'kOrigin' since no further transformations are required.


And yet another alternate approach: If you need to scale the matrix you would
need to also add the transformation matrix, because it needs to be last:


AcGeMatrix3d scaleMat,transMat,coordSysMat;

AcGeVector3d xAxis=normal.perpVector(); // Get a perpendicular vector
(Arbitrary Axis Algorithm) for the X Axis
AcGeVector3d yAxis=zAxis.crossProduct(xAxis); // get the Y Axis
xAxis.rotateBy(rotation,normal);
yAxis.rotateBy(rotation,normal);
scaleMat=scale.operator AcGeMatrix3d(); // Create a scale matrix from your AcGeScale object
transMat.setToTranslation(asVec3d(asDblArray(position)));
coordSysMat.setCoordSystem(AcGePoint3d::kOrigin,xAxis,yAxis,normal);
coordSysMat=scaleMat * CoordSysMat;
mat = transMat * CoordSysMat;


You can use the transformBy() method of an entity along with this matrix to
map world coordinates (WCS) into the MCS (WCS within the block reference), or
invert() the matrix to map MCS coordinates into world coordinates.

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-17 21:37 , Processed in 0.270633 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表