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 & HelpPrograms › help with curve drawing
Pages: 1 2 
help with curve drawing? (Read 1445 times)
help with curve drawing?
Jul 16th, 2006, 8:28pm
 
hi there,
i'm trying to draw a curve and i need some help
i know of curve() and bezier()
but what i'm trying to do is have a pixel start from a pixel on an image,
begin moving on a curve upwards on the z-axis towards another pixel and land on it.
i want basically to simulate something jumping from one pixel to another pixel
and i want to show the jump itself as it happens and not draw a curve out of nowhere
i will be redrawing this one pixel when draw() is looped so that its "next" position will be one pixel further than its current one
so the effect would be of a pixel moving on a (not visible) curve
what i need is some mathematical formula in which to put my variables and control the curvature for its ascent from the origin and descent to the target pixel...
any ideas anyone?
Re: help with curve drawing?
Reply #1 - Jul 17th, 2006, 12:38pm
 
preferably an ellipse
my problem is that i want it in 3d and i haven't found a formula that defines curves in 3d so far
help please! Smiley
Re: help with curve drawing?
Reply #2 - Jul 19th, 2006, 10:55am
 
anyone?
please?
Re: help with curve drawing?
Reply #3 - Jul 19th, 2006, 11:43am
 
post your code please.

F
Re: help with curve drawing?
Reply #4 - Jul 19th, 2006, 12:10pm
 
there is no code yet
the goal is to have a line() statement
tha draws small lines that would be on a curve in 3d
this far what i'm doing is drawing a line from the location to the destination but 50 pixels up on the z axis, and then one directly down to the destination, so as to show that it's some sort of a jump
i need some function, some way to define points in 3 dimensions for this curve
if i'm making myself clear enough
Re: help with curve drawing?
Reply #5 - Jul 19th, 2006, 1:14pm
 
I think your are looking for a line on a sphere. To get a point on a sphere you need this 3 formulars:

x=radius*sin(theta)*cos(phi)
y=radius*sin(theta)*sin(phi)
z=radius*cos(theta)

0>theta<PI; -PI>phi<PI

Take a look on these pic http://de.wikipedia.org/wiki/Bild:Sphere_3d.png to understand whta theta and phi are.
Re: help with curve drawing?
Reply #6 - Jul 19th, 2006, 1:39pm
 
first of all,thanks for replying,i'm really desperate to get this to work
you must have made a typo on the theta and phi
is it 0<theta<PI and -PI<phi<PI ?
if i got it right, theta is the angle between the positive x-axis and the line from the origin to a point P projected onto the xy-plane
and phi is the angle between the z-axis and the line from the origin to the point P, right?
the thing is i don't think i can measure the theta and phi angles of each point.
i can get the r by doing a dist() between the origin and destination pixels and halfing it.
also, in http://en.wikipedia.org/wiki/Sphere i've found that
x=x0+r*sin(theta)*cos(phi)
y=y0+r*sin(theta)*sin(phi)
z=z0+r*cos(theta)
where x0,y0,z0 are the co-ordinates for the center, the origin of the circle.
in that case,would x0,y0,z0 be the co-ordinates of the pixel in the exact middle of the distance between my origin point and my destination point?
if so,how can i find that?
an idea would be to increment the theta and phi within their boundaries by small amounts and draw the co-ordinates that come out of that calculation
do you think that would work?
Re: help with curve drawing?
Reply #7 - Jul 19th, 2006, 1:56pm
 
Sorry, 0<theta<PI and -PI<phi<PI is the right one.
Code:

void setup(){
size(300,300,P3D);
}
void draw(){
background(255);
int steps=50;
float radius=100;
float phi=0;
translate(width/2,height/2);
rotateX(radians(mouseX));
rotateZ(radians(mouseY));
beginShape(LINE_STRIP);
for(int i=0;i<steps;i++){
float theta=-PI+TWO_PI/(steps-1)*i;
float x=radius*sin(theta)*cos(phi);
float y=radius*sin(theta)*sin(phi);
float z=radius*cos(theta);
vertex(x,y,z);
}
endShape();
}
Re: help with curve drawing?
Reply #8 - Jul 19th, 2006, 2:19pm
 
that's way cool
what i want in essence is half of that line and i want to
draw it slowly so it looks like something takes off from one pixel
and lands on another
so,is this what i do?
pass half of the distance between the pixels as the radius
and then keep the for loop but instead draw small lines
incrementally as steps increases?
Re: help with curve drawing?
Reply #9 - Jul 19th, 2006, 2:46pm
 
so this will draw a trajectory of half a circle?

int steps=100;
int i=0;

void setup(){
 size(300,300,P3D);
}
void draw(){
 background(255);
 framerate(10);
 float radius=100;
 float phi=0;
 translate(width/2,height/2);
 rotateX(radians(mouseX));
 rotateZ(radians(mouseY));

   float theta=-PI+TWO_PI/(steps-1)*i;
   float x=radius*sin(theta)*cos(phi);
   float y=radius*sin(theta)*sin(phi);
   float z=radius*cos(theta);
   line(x-2,y-2,z-2, x,y,z);
   i++;
   if (i==50)
   noLoop();
}
Re: help with curve drawing?
Reply #10 - Jul 19th, 2006, 8:33pm
 
what i want to do is put this half-circle drawing bit into my sketch.


what i had been doing thus far is draw a line from the location pixel to 50 pixels above(on the z axis) the destination pixel and then one directly down to it. what i want to do is have a small line move along a "line on a sphere" as you said and draw a half-circle trajectory from the location pixel to the destination pixel and then stop there.
i can't seem to make it work
please help
i promise it will be the last thing i will ask of you :)
Re: help with curve drawing?
Reply #11 - Jul 20th, 2006, 1:17am
 
also, correct me if i'm wrong, but i think you are drawing sort of an equator to the sphere, changing the theta,which is the angle of the projection of the point to the xy with the x axis.
i'd like a line vertical to the equator
do you have an equation for phi as well?
i think that's the one i need to work with and have theta as 0
Re: help with curve drawing?
Reply #12 - Jul 20th, 2006, 12:43pm
 
i found some other formulas according to which you have to add the origin of the sphere to the x,y,z coordinates
with a circle whose origin is 0,0,0 you dont have to do that
but since my sphere will be different each time, i'd need the half way pixel between location and destination, right?
furthermore, since you've set phi as zero,you don't need to calculate your y because it will always be 0 since sin(0)=0;
Re: help with curve drawing?
Reply #13 - Jul 20th, 2006, 10:53pm
 
if anyone can help with this curve i'd be forever grateful
it's the last thing i need to sort out
thanks
Re: help with curve drawing?
Reply #14 - Jul 21st, 2006, 11:21pm
 
please? Smiley
Pages: 1 2