Problem or error with Polyline.getTagentAtIndex()


#1

Hi!

I’m using polylines to extract the tangents and normals from a polyline. I’m using the getTagentAtIndex() method. I don’t know if I’m doing something wrong or there’s some bug, or there’s another way to do the same.

I get the vectors with this:

vector<ofPoint> vertices = myPolyline.getVertices();
for(int i=0; i<vertices.size(); i++) {
    ofVec3f tg = myPolyline.getTangentAtIndex(i);
    ofVec3f nn = myPolyline.getNormalAtIndex(i);
    ofVec3f rr = tg.getCrossed(nn);
}

But I’ve got some error when the point is one of those I used to generate my polyline with .curveTo():

// spiral
for(int i=0; i<nPts; i++) {
    float xx = 400*sin(i*TWO_PI/nPts*3);
    float yy = 400*cos(i*TWO_PI/nPts*3);
    float zz = i*200;
    ofPoint pt = ofPoint(xx,yy,zz);
    myPolyline.curveTo(pt);
}

Al tangents and normals are OK except those corresponding to the originals points.

This is an image of the result. The vertex with numbers are the original points. Red lines ar tangents at each vertex.

Thanks for your comments!


#2

This sounds like a bug, can you open an issue in github?


#3

Of Course.

Gracias Arturo!


#4

The issue is opened, but I’ve solved temporaly the problem doing a simplify() to the polyLine. All things about polyline are recalculated correctly.

// spiral
for(int i=0; i<nPts; i++) {
float xx = 400sin(iTWO_PI/nPts3);
float yy = 400
cos(iTWO_PI/nPts3);
float zz = i*200;
ofPoint pt = ofPoint(xx,yy,zz);
myPolyline.curveTo(pt);
}

myPolyline.simplify(); // <<<==== This


#5

Just for cross-reference: issue is tracked here: https://github.com/openframeworks/openFrameworks/issues/5451