Processing Forum
Now, see that greatAngle? It is the bending angle, i.e. for greatAngle = 180, the spring should touch the groud with both sides. The basic idea was to compute the section of greatAngle a related to the current circle of points, and multiply each point's x for cos( a), and y for sin( a).import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
PeasyCam camera;
float ellipseRadius = 20;
float ang = 0;
float ellipseDetail = 40;
float initCoords[][] = new float[3][int(ellipseDetail)+1];
float steps,stepSize;
float cylHeight=200;
float greatAngle=180;
float jStepDec,jAngleSec, jAngRad;
void setup(){
size(600, 600, P3D);
//size(400, 400, P3D);
camera = new PeasyCam(this,width/2,height/2,0,int((height/2.0)/tan(PI*60.0/360)));
background(100);
steps=20;
noFill();
stroke(10);
stepSize=cylHeight/steps;
}
void draw(){
ang=0;
background(255);
translate(width/2, height/2, 0);
beginShape();
for (float j=0; j<steps; j++) {
//To be used for spring curvature (BUT HOW)
jStepDec=j/steps;
jAngleSec=greatAngle*jStepDec;
jAngRad=radians(jAngleSec);
for (int i=0; i<=ellipseDetail; i++){
initCoords[0][i] = sin(radians(ang))*ellipseRadius + cos(radians(ang))*ellipseRadius;
initCoords[1][i] = j*stepSize;
initCoords[2][i] = cos(radians(ang))*ellipseRadius - sin(radians(ang))*ellipseRadius;
ang+=360.0/ellipseDetail;
point(initCoords[0][i],initCoords[1][i],initCoords[2][i]);
}
}
endShape();
}