Circular path(revolution)

hi everyone…i m trying to revolve a sphere around other sphere in circular path…but i m not achieving that…

well rotation is no problem…but i simply can't revolve my sphere around the other horizontally…

any help…

I think this will help; Parametric Equation of a Circle.



x = a + rcos(t)

y = b + r
sin(t)



(1), Wikipedia

(2), Wolfram

You can just use the node system.



Have the second sphere attached to a node. Set the local translation of the sphere to your orbital radius.

Then rotate the node. The sphere will orbit around it.

thanks for ur advices…

x=a+rcos(t) and y= b+ rsin(t) didn't quite work…



but i think correct parametric equation of circle is:

x=acos(t)

y= a
sin(t)



and it worked like a charm…



x and y is a coordinate or position of my second sphere which is a earth ,i have kept z coordinate to 0…

a is a distance of a earth from a centre of the first sphere which is a sun…

and t is an angle between "line joining position of earth and centre of sun" and the x axis passing through the centre of sun…



so here is the my program to revolve my earth around sun…

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package padam._3dapp;

/**
*
* @author Netbeans
*/
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.light.PointLight;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.LightState;

public class SpaceCircle extends SimpleGame{

    private float ex=40,ey=0,angle=0;
    private Sphere earth;
    public static void main(String[] args)
{
    SpaceCircle app=new SpaceCircle();
    app.setConfigShowMode(ConfigShowMode.AlwaysShow);
    app.start();
}

protected void simpleInitGame()
{
    PointLight plight;
    LightState lstate;
    cam.setLocation(new Vector3f(0,15,95));
    Sphere sun=new Sphere("sun",30,30,10);
    sun.setModelBound(new BoundingSphere());
    sun.updateModelBound();
    plight=new PointLight();
    plight.setLocation(new Vector3f(10,15,10));
    plight.setDiffuse(ColorRGBA.yellow);
    plight.setEnabled(true);
    lstate=display.getRenderer().createLightState();
    lstate.attach(plight);
    rootNode.setRenderState(lstate);

    earth=new Sphere("Earth",30,30,5);
    earth.setLocalTranslation(new Vector3f(40,0,0));
       
    rootNode.attachChild(earth);
    rootNode.attachChild(sun);
}

@Override
protected void simpleUpdate()
{
    if(angle>360)
    {
        angle=0;
    }
    angle+=0.01f;
    ex=40*FastMath.cos(angle);
    ey=40*FastMath.sin(angle);
    earth.setLocalTranslation(new Vector3f(ex,ey,0));
}
}


my earth is revolving perfectly..........in this program my earth is starting from east than moves towards north of sun then to west of sun then to south and back to east of sun and this goes on..........but i want to revolve it horizontally.....which i m not able to do it....
i mean i want my earth to start from west then goes to east and then backside of my sun...then again west of sun to east of sun.......any help..........

Using your current framework, you could do this


@Override
protected void simpleUpdate()
{
    if(angle>360)
    {
        angle=0;
    }
    else angle+=0.01f;

    float amt;
    if(angle > 180) amt = 360 - angle;
    else amt = angle;

   ex=40*FastMath.cos(amt);
   ey=40*FastMath.sin(amt);
    earth.setLocalTranslation(new Vector3f(ex,ey,0));
}



I think Alric's solution is much cleaner though as it uses the power of jme.  If you have time to play around, you could use this method along with a SpatialTransformer with a max rotation about y-axis as 180 and set the controller repeat type to RT_CYCLE.  See com.jmetest.TutorialGuide.HelloAnimation for an example.

thanks anubis for ur help…but it didn't work as i wanted…its the same as my previous code was working…



and i checked HelloAnimation, there revolution is working perfectly in x axis and z axis…but it isn't working for y axis…

when i try to revolve the pivot node in y axis(new Vector3f(0,1,0) on quartenion) it just rotates the box around the fixed point…it just rotates but doesn't revolve…



and in my code above…shall i just set my camera location in a position so that it would look exactly as i want to be…

Did you add the earth to a node first, and set the local translation of the earth to your orbital radius and then attach the SpatialTransformer to the node?



Node n = new Node();
n.attachChild(earth);
earth.getLocalTranslation().set(-40,0,0);
earth.updateWorldVectors();
n.updateGeometricStrate(0,true);



Also, I misunderstood your initial horizontal movement and had it going left to right and then right to left but you want it to move left to right and then start at left side again and move to the right.  So the repeat type should be RT_WRAP and not RT_CLAMP.  Also, in the original code it should be angle - 180 instead of 360 - angle.
padam said:

thanks for ur advices......
x=a+r*cos(t) and y= b+ r*sin(t) didn't quite work...........

but i think correct parametric equation of circle is:
x=a*cos(t)
y= a*sin(t)

and it worked like a charm............


r is just the radius which you assumed to be 1.

thanks once again for your help…

i did it what i want but with my version of code…

i just kept x and z coordinates varying and kept the y axis to 0…and it worked what i want…

my code is:

if(angle>360)
    {
        angle=0;
    }
    else
    angle+=0.01f;
    ex=40*FastMath.cos(angle);
    ez=40*FastMath.sin(angle);
    earth.setLocalTranslation(new Vector3f(ex,0,ez));




and this is my full code of my version......


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package padam._3dapp;

/**
 *
 * @author Netbeans
 */
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.light.PointLight;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.LightState;

public class SpaceCircle extends SimpleGame{

    private float ex=40,ez=0,angle=0;
    private Sphere earth;
    public static void main(String[] args)
{
    SpaceCircle app=new SpaceCircle();
    app.setConfigShowMode(ConfigShowMode.AlwaysShow);
    app.start();
}

protected void simpleInitGame()
{
    PointLight plight;
    LightState lstate;
    cam.setLocation(new Vector3f(0,15,95));
    Sphere sun=new Sphere("sun",30,30,10);
    sun.setModelBound(new BoundingSphere());
    sun.updateModelBound();
    plight=new PointLight();
    plight.setLocation(new Vector3f(10,15,10));
    plight.setDiffuse(ColorRGBA.yellow);
    plight.setEnabled(true);
    lstate=display.getRenderer().createLightState();
    lstate.attach(plight);
    rootNode.setRenderState(lstate);

    earth=new Sphere("Earth",30,30,5);
    earth.setLocalTranslation(new Vector3f(40,0,0));
       
    rootNode.attachChild(earth);
    rootNode.attachChild(sun);
 }

@Override
protected void simpleUpdate()
{
    if(angle>360)
    {
        angle=0;
    }
    else
    angle+=0.01f;
    ex=40*FastMath.cos(angle);
    ez=40*FastMath.sin(angle);
    earth.setLocalTranslation(new Vector3f(ex,0,ez));
}
}


ok nw i have achieved what i want...but i couldn't get the very same result using spatialtransformer(what alric and anubis adviced me).........could u please give a small code snippet to get the same result what i have got using above code...........

padam said:

hi everyone.......i m trying to revolve a sphere around other sphere in circular path....


Did you check out jmetest.scene.TestRotateAboutPoint? it seems to be exactly what you try to do.
No funny cos() and sin() needed, just use the Scene Graph like Alric suggested.

thanks core…i checked the TestRotateAboutPoint class…really no funny cos and sin headache involve there…

so actually today i learned about nodes and benefits to attach my objects to a node…

thanks everyone for their help…



JME- I AM LOVING IT…