how to draw a spline3d closed curve?
in
Contributed Library Questions
•
2 years ago
hi, I just want to draw a closed spline3D curve (using toxiclibs), but I cant get the first and last handles join together nicely. They connect themselves with no curve. Could anyone help me with this? Thank you anyway.
This is the sketch:
import processing.opengl.*;
import toxi.geom.*;
int fondo = 40;
int cant = 3;
int segmentos = 30;
Vec3D[] handles = new Vec3D[cant + 1];
void setup()
{
size(300, 400, OPENGL);
for(int i = 0; i < handles.length; i++)
{
if(i == handles.length - 1)
{
handles[i] = new Vec3D(handles[0]);
}
else
{
handles[i] = new Vec3D(random(width-50)+25, random(height-50)+25, 0);
}
}
}
void draw()
{
background(fondo);
noFill();
stroke(255);
strokeWeight(3);
Spline3D spline = new Spline3D(handles);
List<Vec3D> vertices = spline.computeVertices(segmentos);
for(int i = 0; i < vertices.size(); i++)
{
stroke(i*10, 0, 0);
Vec3D v = new Vec3D(vertices.get(i).x, vertices.get(i).y, vertices.get(i).z);
point(v.x, v.y, 0);
}
stroke(0);
strokeWeight(6);
for(int i = 1; i < handles.length - 1; i++)
{
stroke(map(i, 0, handles.length - 1, 0, 255), map(i, 0, handles.length - 1, 255, 0), 0);
point(handles[i].x, handles[i].y);
}
}
void mouseClicked()
{
setup();
}
1