在Java3D中使用AxisAngle4d旋转圆柱体
我目前正在尝试旋转圆柱体,使其与给定向量对齐(因此“绘制”向量)。此外,这应在特定时间后更新,并且应根据更改的向量再次绘制向量。 我使用AxisAngle4d围绕原点旋转圆柱体。旋转参数是使用轴的叉积和两个矢量之间的角度作为角度来计算的 以下是基本代码:在Java3D中使用AxisAngle4d旋转圆柱体,java,vector,rotation,Java,Vector,Rotation,我目前正在尝试旋转圆柱体,使其与给定向量对齐(因此“绘制”向量)。此外,这应在特定时间后更新,并且应根据更改的向量再次绘制向量。 我使用AxisAngle4d围绕原点旋转圆柱体。旋转参数是使用轴的叉积和两个矢量之间的角度作为角度来计算的 以下是基本代码: //Returns rotation axis and rotation angle public AxisAngle4d getRotation(Vector3d start, Vector3d target) { //Get rot
//Returns rotation axis and rotation angle
public AxisAngle4d getRotation(Vector3d start, Vector3d target)
{
//Get rotation axis
Vector3d cross=new Vector3d();
// TODO: Catch small angles (ignore cross product)
cross.cross(start,target);
//Get rotation angle between start and target
double angle=start.angle(target);
//Create AxisAngle4f with rotation axis and angle parameters
AxisAngle4d rot = new AxisAngle4d(cross,angle);
//Test
System.out.println("Rot: "+rot);
//return rotation parameters
return rot;
}
//Rotates arrow to target vector
public void rotate(TransformGroup object,Vector3d startVector,Vector3d targetVector)
{
//TODO: Always reset rotation to 0?
//new Transform3D containing rotation information
Transform3D rotator = new Transform3D();
//Set rotation so it will rotate to targetVector
rotator.setRotation(getRotation(startVector,targetVector));
//get previous rotation and copy into temp
Transform3D temp3d = new Transform3D();
object.getTransform(temp3d);
//combine two rotations
temp3d.mul(rotator);
//Set Transform to new rotation
object.setTransform(temp3d);
}
//perform Rotations after update
public void updateRotation()
{
//call rotator for each arrow
rotate(axisArrowX,this.temp_satOrientationX,this.satOrientationX);
rotate(axisArrowY,this.temp_satOrientationY,this.satOrientationY);
rotate(axisArrowZ,this.temp_satOrientationZ,this.satOrientationZ);
}
问题是气缸无法正确旋转。我检查了AxisAngle4d,它似乎是正确的,但执行的旋转不对应
有什么想法吗?怎么了?(尤其是在旋转方法中)
谢谢,汤姆