This will give you a cumulative rotation. I use it to rotate my view
platform
when I want to rotate my view around the origin, but it should work for
anything.
/**
Rotates the specified transform about an axis
Specify "X", "Y", or "Z" for the axis.
If the string is not recognized, prints a message but continues
and the matrix is not transformed.
*/
public static Transform3D rotateAboutAxis(String axis, Transform3D
transform, double degrees) {
// now rotation and translation are stored
Vector3d translation = new Vector3d();
Matrix3d rotation = new Matrix3d();
transform.get(rotation);
transform.get(translation);
Matrix4d identity = new Matrix4d();
identity.setIdentity();
Matrix4d t0 = new Matrix4d(identity);
Matrix4d r0 = new Matrix4d(identity);
Matrix4d r1 = new Matrix4d(identity);
Matrix3d increment = new Matrix3d();
if(axis.equals("X"))
increment.rotX(Math.toRadians(degrees));
else if(axis.equals("Y"))
increment.rotY(Math.toRadians(degrees));
else if(axis.equals("Z"))
increment.rotZ(Math.toRadians(degrees));
else
System.out.println("Invalid axis specified");
r1.setRotation(increment);
t0.setTranslation(translation);
t0.setRotation(rotation);
t0.mul(r1,t0); // rotate again, affects position
Transform3D newTransform = new Transform3D();
newTransform.set(t0);
return newTransform;
}
-----Original Message-----
From: Chet Urata [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 19, 2003 7:45 PM
To: [EMAIL PROTECTED]
Subject: Re: [JAVA3D] problem in angle setting in java 3D using
Transform3D
Greetings, Naveen,
Just to save the big guns from sending this out, I'll offer that one
problem right off the bat is that your series of rotations
Rot.rotX(angleX);
Rot.rotY(angleY);
Rot.rotZ(angleZ);
results in only Rot.rotZ(angleZ) being the net effect. This is because each
call to .rot#() wipes out the previous contents of the Transform. You'll
have to do something else, such as create a separate Transform3D to hold a
new rotation and multiply it in, but there are many other solutions.
It's a problem that I found out about the hard way, too, and, to me, it's
not blatantly obvious from the documentation.
Regards,
c h e t !
--- Naveen Babu Chikkala <[EMAIL PROTECTED]> wrote:
> hello
> i am facing some problem like angle seting with x y z planes . my
> basic problem is "I NEED TO PLOTE A CYLINDER IN X Y Z PLANE with
> some dynamic anggles "
>
> i am using below code
> Transform3D t3d = new Transform3D();
>
> this t3d set to mid point of cylinder
>
> Transform3D Rot = new Transform3D();
> Rot.rotX(angleX);
> Rot.rotY(angleY);
> Rot.rotZ(angleZ);
> Rot.mul(t3d);
>
> angleX,angleY,angleZ are the method for calculating angle with
> respectx y z lines
> method look like this
>
>
> -----------------
> public double getAngleWithX_Axis(Point3f p1,Point3f p2)
> {
> Point3f p1_l=p1;
> Point3f p2_l=p2;
>
> float x1=0.0f;
> float y1=0.0f;
> float z1=0.0f;
>
> float x2=2.0f;
> float y2=0.0f;
> float z2=0.0f;
> //---second line
> /*
> p2
> |---------------
> |
> p1 |
> |
> */
> float x3=p1_l.x;
> float y3=p1_l.y;
> float z3=p1_l.z;
>
> float x4=p2_l.x;
> float y4=p2_l.y;
> float z4=p2_l.z;
>
> double a0,a1,b0,b1,c0,c1;
> a0=x2-x1;b0=y2-y1;c0=z2-z1;
> a1=x4-x3;b1=y4-y3;c1=z4-z3;
>
> double firstSqure= Math.sqrt(((a0*a0)+(b0*b0)+(c0*c0)));// p1
> double secondSqure= Math.sqrt(((a1*a1)+(b1*b1)+(c1*c1)));//p2
> double sum=((a0*a1)+(b0*b1)+(c0*c1))/((firstSqure)*(secondSqure));
> double theta=Math.acos(sum);
> return theta;
> }
> -----------------
> i don't know where the problem in in my angle calculation or in my
> java3d
> implementation.
>
> waiting for feedback
>
> Regards
>
> naveen
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in
> the body
> of the message "signoff JAVA3D-INTEREST". For general help, send
> email to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".