在Java3D中使用AxisAngle4d旋转圆柱体

时间:2015-05-30 12:12:50

标签: java vector rotation

我正在尝试旋转圆柱体,使其与给定的矢量对齐(因此“绘制”矢量)。此外,这应该在特定时间之后更新,并且应该相应于更改的矢量再次绘制矢量。 我正在使用AxisAngle4d围绕原点旋转圆柱体。使用轴的叉积和2个矢量之间的角度作为角度...

计算旋转参数

以下是基本代码:

//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,看起来是正确的,但执行的旋转不对应。

任何想法都错了吗? (特别是在旋转方法中)

谢谢,汤姆

0 个答案:

没有答案