I am new in using Processing and, also, new asking something here
I hope that will get some help here and solve my problem.
There is an equation of elliptic curve that I would like to draw using Processing.
I wrote a code that calculates some points that belong to the curve, but I didn’t have any success in connecting them.
Here is my code:
void setup()
{
size(500,500);
} // end of setup() function
void draw()
{
background(0);
// drawing elliptic curve y^2=x^3+7
//drawing Cartesian coordinate system
//vertical line
line(width/2,0,width/2,height);
//horizontal line
line(0,height/2,width, height/2);
// the starting point; zero point of elliptic curve
float Xpom=-pow(7,1/3);
float x0=Xpom+width/2;
float y0=height/2;
ellipse(20*Xpom+width/2,height/2,20,20);
point(20*Xpom+width/2, height/2);
for(int i=1;i<width/2;i++) // translation of points
{
//x coordinate
float x1=Xpom+i;
float y1=sqrt(pow(x1,3)+7);
// coordinates of the center of ellipse
float xf=20*x1+width/2;
float yf1=20*y1+height/2;
// drawing ellipse
stroke(255);
strokeWeight(2);
fill(127);
ellipse(xf,yf1,20,20);
point(xf,yf1);
float yf2=height-yf1;
stroke(255);
strokeWeight(2);
fill(127);
ellipse(xf,yf2,20,20);
point(xf,yf2);
}// end of for loop
}// end of draw() function
I draw a Cartesian coordinate system and points and ellipses that follow the shape of the given curve. I wanted, as I said, to connect them. The first idea was to save values that I’ve got in array of PVector and then to use those values to connect them using curveVertex. I couldn’t do that.
Please edit your post and add tripple back thicks before and after your code block: ``` as this will format your code properly here in the forum. Not doing this affects your original code format and some characters are removed from your original code.
You can use arrays to store the x and y coordinates. You can also use an array of vectors or you can use a dynamic size array of vectors by using an ArrayList. For example:
Change the value of deltaX if you want finer distances between the points. You can also use curve, Bezier, etc. Explore the reference and find the function that is more convenient for your sketch.
These can be interesting either as tools to use off-the-shelf, or the library interface / code itself can be interesting for how others have approached designing solutions to similar problems.