'Processing Java -- Find the length of a multi-point curve?
I'm working on a sketch which draws a multi-point curve using curveVertex, and I need to calculate the length of the resulting curve (both the total curve length, and the length of each individual segment as well). I've found this page, which deals with bez curve length, but it's from several years ago, and I'm wondering if there's a more modern way to handle this?
Here's a quick demo of what I'm looking for:
class curveNode() {
int x,y,z;
float startPosition, segmentLength;
curveNode() {
x = int(random(30));
y = int(random(30));
z = int(random(30));
}
}
void draw() {
// Make some nodes
curveNode[] nodeArray = new curveNode[5];
for (int i=0;i<nodeArray.length;i++) {
nodeArray[i] = new curveNode();
}
// draw the curve
noFill();
beginShape();
for (int i=0;i<nodeArray.length;i++) {
curveVertex(nodeArray[i].x, nodeArray[i].y, nodeArray[i].z);
}
endShape();
// This is where I need help!
// calculate the distances
float lengthRunningTotal = 0;
float segmentLength = 0;
for (int i=0;i<nodeArray.length-1;i++) {
nodeArray[i].startPosition = distanceRunningTotal;
// ???? calculate segment length ????
// float segmentLength = nodeArray[1] ??? nodeArray[n+1]
// lengthRunningTotal += segmentLength;
}
// TK fill values for the final node in the array.
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
