本文整理汇总了C++中ofPolyline::getClosestPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ ofPolyline::getClosestPoint方法的具体用法?C++ ofPolyline::getClosestPoint怎么用?C++ ofPolyline::getClosestPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofPolyline
的用法示例。
在下文中一共展示了ofPolyline::getClosestPoint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setIndex
void form::setIndex(msa::physics::Particle3D *_p, ofPolyline &_master, ofPolyline &_slave, int _ind) {
unsigned int mind = 0;
unsigned int sind = 0;
ofPoint mcpt = _master.getClosestPoint(_p->getPosition(), &mind);
ofPoint scpt = _slave.getClosestPoint(_p->getPosition(), &sind);
float mdist = mcpt.distance(_p->getPosition());
float sdist = scpt.distance(_p->getPosition());
//if (mdist < sdist) {
if (mdist < mTol) {
mMasterEdgeParticles.push_back(new part_and_index(_p,mind, _ind));
}
//} else {
if (sdist < mTol) {
mSlaveEdgeParticles.push_back(new part_and_index(_p,sind, _ind));
}
//}
}
示例2: buildMesh
//.........这里部分代码省略.........
ofEllipse (ex, ey, 9, 9);
}
}
//---------------
// ADD VERTICES TO THE MESH.
vector<ofPoint> poly01RSpts = poly01RS.getVertices();
vector<ofPoint> poly21RSpts = poly21RS.getVertices();
int nPoly01RSpts = poly01RSpts.size();
int nPoly21RSpts = poly21RSpts.size();
if ((nPoly01RSpts == nPoly21RSpts) &&
(nPoly01RSpts == (N_FINGER_LENGTH_SAMPLES+1))){
for (int i=0; i<=N_FINGER_LENGTH_SAMPLES; i++){
float px01 = poly01RSpts[i].x;
float py01 = poly01RSpts[i].y;
float px21 = poly21RSpts[i].x;
float py21 = poly21RSpts[i].y;
if (i == N_FINGER_LENGTH_SAMPLES){
// Special case for the tip.
// N.B., px01 and px21 are the same point
float qx01 = (poly01RSpts[N_FINGER_LENGTH_SAMPLES-1].x + px01)/2.0;
float qy01 = (poly01RSpts[N_FINGER_LENGTH_SAMPLES-1].y + py01)/2.0;
ofPoint q01 = ofPoint(qx01, qy01);
float qx21 = (poly21RSpts[N_FINGER_LENGTH_SAMPLES-1].x + px21)/2.0;
float qy21 = (poly21RSpts[N_FINGER_LENGTH_SAMPLES-1].y + py21)/2.0;
ofPoint q21 = ofPoint(qx21, qy21);
ofPoint QA = handContour.getClosestPoint(q01);
ofPoint QB = handContour.getClosestPoint(q21);
ofEllipse(QA.x, QA.y, 2, 2);
ofEllipse(px01, py01, 2, 2);
ofEllipse(QB.x, QB.y, 2, 2);
handMesh.addVertex(ofPoint(QA.x, QA.y,0));
handMesh.addVertex(ofPoint(px01, py01,0));
handMesh.addVertex(ofPoint(QB.x, QB.y,0));
} else {
// The usual case, up the sides of the finger.
if (f < 2){
for (int j=0; j<N_FINGER_WIDTH_SAMPLES; j++){
float ex = ofMap(j, 0,N_FINGER_WIDTH_SAMPLES-1, px01,px21);
float ey = ofMap(j, 0,N_FINGER_WIDTH_SAMPLES-1, py01,py21);
ofEllipse(ex,ey, 2, 2);
handMesh.addVertex(ofPoint(ex,ey,0));
}
} else {
// skip the 0th point for fingers 2,3,4,
// because these are shared vertices with points we've already laid.
for (int j=0; j<N_FINGER_WIDTH_SAMPLES; j++){
float ex = ofMap(j, 0,N_FINGER_WIDTH_SAMPLES-1, px01,px21);
float ey = ofMap(j, 0,N_FINGER_WIDTH_SAMPLES-1, py01,py21);
ofEllipse(ex,ey, 2, 2);
if ((j==0) && (i==0)){
;
} else {
handMesh.addVertex(ofPoint(ex,ey,0));
}
示例3: draw
//--------------------------------------------------------------
void ofApp::draw(){
if(poly.size() < 2) return;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateY(rotAngle);
ofSetColor(255, 255, 255);
poly.draw();
ofSetColor(0, 255, 0);
ofSetRectMode(OF_RECTMODE_CENTER);
glPointSize(5);
glBegin(GL_POINTS);
for(int i=0; i<poly.size(); i++) {
ofPoint p = poly[i];
glVertex3f(p.x, p.y, p.z);
}
glEnd();
for(int i=0; i<poly.size(); i++) {
ofPoint p = poly[i];
ofSetColor(255, 0, 0);
ofLine(p, p + poly.getTangentAtIndex(i) * 20);
ofSetColor(0, 255, 0);
ofLine(p, p + poly.getNormalAtIndex(i) * 20);
ofSetColor(0, 128, 255);
ofLine(p, p + poly.getRotationAtIndex(i) * 20);
}
float totalLength = poly.getPerimeter();
float totalArea = poly.getArea();
ofPoint nearestPoint = poly.getClosestPoint(ofPoint(mouseX-ofGetWidth()/2, mouseY-ofGetHeight()/2), &nearestIndex);
ofPoint nearestDataPoint = poly[nearestIndex];
float lengthAtIndex = poly.getLengthAtIndex(nearestIndex);
ofPoint pointAtIndex = poly.getPointAtIndexInterpolated(nearestIndex);
ofPoint pointAtLength = poly.getPointAtLength(lengthAtIndex);
ofPoint pointAtPercent = poly.getPointAtPercent(lengthAtIndex / totalLength);
float indexAtLength = poly.getIndexAtLength(lengthAtIndex);
float sinTime = ofMap(sin(ofGetElapsedTimef() * 0.5), -1, 1, 0, 1);
float sinIndex = sinTime * (poly.isClosed() ? poly.size() : (poly.size()-1)); // sinTime mapped to indices direct
float sinIndexLength = poly.getIndexAtPercent(sinTime); // sinTime mapped to indices based on length
float lengthAtIndexSin = poly.getLengthAtIndexInterpolated(sinIndex);
ofPoint pointAtIndexSin = poly.getPointAtIndexInterpolated(sinIndex);
ofPoint pointAtPercentSin = poly.getPointAtPercent(sinTime);
float angleAtIndex = poly.getAngleAtIndex(nearestIndex);
float angleAtIndexSin = poly.getAngleAtIndexInterpolated(sinIndex);
ofVec3f rotAtIndex = poly.getRotationAtIndex(nearestIndex);
ofVec3f rotAtIndexSin = poly.getRotationAtIndexInterpolated(sinIndex);
float rotMagAtIndex = rotAtIndex.length();
float rotMagAtIndexSin = rotAtIndexSin.length();
ofVec3f normalAtIndex = poly.getNormalAtIndex(nearestIndex);
ofVec3f tangentAtIndexSin = poly.getTangentAtIndexInterpolated(sinIndex);
ofVec3f normalAtIndexSin = poly.getNormalAtIndexInterpolated(sinIndex);
ofVec3f rotationAtIndexSin = poly.getRotationAtIndexInterpolated(sinIndex);
ofNoFill();
ofSetLineWidth(2);
ofSetColor(255, 0, 0);
ofCircle(nearestPoint, 5);
ofSetColor(255, 255, 0);
ofCircle(nearestDataPoint, 7);
// interpolating on indices
{
ofPoint p = poly.getPointAtIndexInterpolated(sinIndex);
ofSetColor(0, 255, 255);
ofCircle(p, 10);
ofSetColor(255, 0, 0);
ofLine(p, p + poly.getTangentAtIndexInterpolated(sinIndex) * 60);
ofSetColor(0, 255, 0);
ofLine(p, p + poly.getNormalAtIndexInterpolated(sinIndex) * 60);
ofSetColor(0, 128, 255);
ofLine(p, p + poly.getRotationAtIndexInterpolated(sinIndex) * 60);
}
// interpolating on length percentages
{
ofPoint p = poly.getPointAtIndexInterpolated(sinIndexLength);
ofSetColor(255, 0, 255);
//.........这里部分代码省略.........