We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Building a graphic of a solar system
Page Index Toggle Pages: 1
Building a graphic of a solar system (Read 1621 times)
Building a graphic of a solar system
Nov 1st, 2006, 5:44pm
 
hey..im wondering if anyone can help me..im developing a graphic of the solar system in a 2d format but from a perspective as if u were looking down diagonally from a 3d view.im trying to develop a curve for each trajectory of the planet. It relates to the example shown in the learning part of this web site "movement on curves". But i cant seem to develop a curve which will link all the way around for the orbit of each planet..can anyone help me out?
Re: Building a graphic of a solar system
Reply #1 - Nov 1st, 2006, 8:35pm
 
I think it makes sense to use a 3D renderer, regardless if you want more of a 2D rendering style.
Here's a simple simulated example (without any physics).

Code:

Planet p1, p2, p3, p4, p5;
void setup(){
size(400, 400, P3D);
p1 = new Planet(0, 2, #DD33CC);
p2 = new Planet(45, 3, #EE9922);
p3 = new Planet(135, 5, #3399FF);
p4 = new Planet(225, 6, #55EE33);
p5 = new Planet(300, 2, #99FFEE);
}

void draw(){
background(0);
translate(width/2, height/2);
rotateX(radians(55));
p1.orbit(50, 55, 2.4, true);
p2.orbit(120, 132, 1.2, true);
p3.orbit(60, 66, 1.7, true);
p4.orbit(150, 165, 2.75, true);
p5.orbit(20, 22, 1.75, true);
}

class Planet{
float planetOffset;
float planetRadius;
color surface;
float angle;
boolean isPathVisible;

Planet(float planetOffset, float planetRadius, color surface){
angle = planetOffset;
this.planetRadius = planetRadius;
this.surface = surface;
}

void orbit(float ellipticalRadiusX, float ellipticalRadiusY,
float orbitSpeed, boolean isPathVisible){
// draw ellipse first, so it's under the planet
if (isPathVisible){
drawOrbit(ellipticalRadiusX, ellipticalRadiusY);
}

float px = cos(radians(angle))*ellipticalRadiusX;
float py = sin(radians(angle))*ellipticalRadiusY;
fill(surface);
noStroke();
ellipse(px, py, planetRadius*2, planetRadius*2);
angle+=orbitSpeed;
}

void drawOrbit(float ellipticalRadiusX, float ellipticalRadiusY){
stroke(255, 50);
float angle=0;
for (int i=0; i<360; i++){
point(cos(radians(angle))*ellipticalRadiusX,
sin(radians(angle++))*ellipticalRadiusY);
}
}
}


-ira
Re: Building a graphic of a solar system
Reply #2 - Nov 2nd, 2006, 9:52pm
 
No this doesnt help because i need it to rotate around the Sun as if looking from an angle with a curve method.as if u were looking down from the right.THe planets would go diagonally from bottom left to to right and would go behind the Sun.
Re: Building a graphic of a solar system
Reply #3 - Nov 3rd, 2006, 12:04am
 
If you do your drawing in 3D with the sun at the origin and the orbits in the xy plane, all you have to do is call camera() with arguments that place the camera where you want in relation to your drawing, looking at the point you want it to look at (the sun for example). The perspective will be taken care of by the camera transform.
Re: Building a graphic of a solar system
Reply #4 - Nov 3rd, 2006, 12:09am
 
no i cant do it in 3D!!! read the post.if u cant help,dont post.
Re: Building a graphic of a solar system
Reply #5 - Nov 3rd, 2006, 12:32am
 
try something like:

Code:
float angle;
//setup stuff missed, add whatever you need...

void draw()
{
angle+=0.01;

float xpos=(width/2.0)*sin(angle);
float ypos=(height/8.0)*cos(angle);

//draw sun at width/2,height/2

//draw planet at xpos,ypos
}


You'll have to decide for yourself if the planet is in front of the sun if it's y value is hight, or if that's behind, and then draw in the appropriate order.
Re: Building a graphic of a solar system
Reply #6 - Nov 3rd, 2006, 12:58am
 
cool...but whats the angle?is it an int?
Re: Building a graphic of a solar system
Reply #7 - Nov 3rd, 2006, 1:10am
 
thanks for ur help man
Re: Building a graphic of a solar system
Reply #8 - Nov 3rd, 2006, 2:01am
 
can i manipulate the speed man?
Re: Building a graphic of a solar system
Reply #9 - Nov 3rd, 2006, 10:27am
 
You can change the speed by changing the size of the value you add to angle.
Re: Building a graphic of a solar system
Reply #10 - Nov 3rd, 2006, 12:23pm
 
ye thanks man..i did that already.thanks. Smiley
Re: Building a graphic of a solar system
Reply #11 - Nov 3rd, 2006, 2:37pm
 
that worked fine..but im tryin to Add curves for the trajectory of each..any ideas how?
Page Index Toggle Pages: 1