i have a question... i can't get my orbits to align right in java3d. it's for a satellite application, but just by hand, i can't get an x, y, and z rotation of a vertical rotation axis to create what i think it should.
do you see any problems with the following functions? advice?? comments??
-----------------------
----------------------
thanks for any help
do you see any problems with the following functions? advice?? comments??
-----------------------
Code:
//add satellite to branchgroup given inclination, raan, semi-major axis, and period
public int addSatellite(double inclination, double raan, double sma, double period)
{
SATELLITE_COUNT++;
// First, find the point of the orbit which crosses the y-z plane
double x1 = 0;
double y1 = sma * Math.sin(inclination);
double z1 = sma * Math.cos(inclination);
// Next, find the point of the orbit which crosses the x-z plane
double x2 = sma * Math.cos(raan);
double y2 = 0;
double z2 = sma * Math.sin(raan);
// Now that we have two position vectors on the orbital plane,
// we can cross product them to find the normal vector to that plane
double x3 = sma * sma * Math.sin(inclination) * Math.sin(raan);
double y3 = - (sma * sma * Math.cos(inclination) * Math.cos(raan));
double z3 = sma * sma * Math.sin(inclination) * Math.cos(raan);
// We must also convert the vector we just calculated to a vector of angles
double angx = Math.atan(z3/y3);
double angy = raan;
double angz = Math.atan(y3/x3);
Vector3d trans = map(new Vector3d(x1,y1,z1));
sat.addElement( getSatellite(
trans.x, trans.y, trans.z, angx, angy, angz, period
) );
BranchGroup bg = new BranchGroup();
bg.addChild( (TransformGroup)sat.elementAt(SATELLITE_COUNT-1) );
objRoot.addChild(bg);
return SATELLITE_COUNT-1;
}
//create a satellite given an initial position, axis of rotation, and period of rotation
private TransformGroup getSatellite(double x, double y, double z, double angleX, double angleY, double angleZ, double period) {
TransformGroup sat1RotTrans = new TransformGroup();
sat1RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
sat1RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
sat1RotTrans.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
// Set the satellite's properties
Transform3D t = new Transform3D();
Vector3d satPos1 = new Vector3d(x, y, z);
t.set(satPos1);
TransformGroup sat1Trans = new TransformGroup(t);
sat1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
sat1Trans.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
sat1RotTrans.addChild(sat1Trans);
Material m = new Material();
Appearance appSat1 = new Appearance();
m.setLightingEnable(true);
ColoringAttributes caSat1 = new ColoringAttributes();
caSat1.setColor(satColor1);
appSat1.setColoringAttributes(caSat1);
appSat1.setMaterial(m);
sat1Trans.addChild(
new Sphere(0.02f, appSat1)
);
//create axis of rotation
Transform3D rotAxis = new Transform3D();
Transform3D rotX = new Transform3D();
rotX.rotX(angleX);
rotAxis.mul(rotX);
Transform3D rotY = new Transform3D();
rotY.rotY(angleY);
rotAxis.mul(rotY);
Transform3D rotZ = new Transform3D();
rotZ.rotZ(angleZ);
rotAxis.mul(rotZ);
//create rotation interpolation
if (period > 0) {
Alpha rotor1Alpha = new Alpha(
-1, (int)(1000*period)
);
RotationInterpolator rotator1 = new RotationInterpolator(
rotor1Alpha, sat1RotTrans, rotAxis,
0.0f, (float) Math.PI*2.0f
);
rotator1.setSchedulingBounds(bounds);
sat1RotTrans.addChild(rotator1);
}
return sat1RotTrans;
}
thanks for any help