本文整理汇总了C++中ofVec2f::distance方法的典型用法代码示例。如果您正苦于以下问题:C++ ofVec2f::distance方法的具体用法?C++ ofVec2f::distance怎么用?C++ ofVec2f::distance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofVec2f
的用法示例。
在下文中一共展示了ofVec2f::distance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: interaccion_point
void menu::interaccion_point(ofVec2f ptF, bool isNeg) {
float minDis = ofGetHeight()/3.0;// (isNeg)? 400 : 200;
float minDis2 = minDis*minDis;
float ff = 1.0;
float fFuerza = 45.0;
if(ptF.distance(centro)<distConf) {
// if(ptF.squareDistance(centro)<distConf) {
if(isNeg) {
// Atrae circulos y repele boxes
for(int i=0; i<circles.size(); i++) {
// float dis = ptF.distance(circles[i].get()->getPosition());
float dis2 = ptF.squareDistance(circles[i].get()->getPosition());
// if(dis < minDis)
// if(dis2 < minDis2)
// circles[i].get()->addRepulsionForce(ptF, ff*1.4f*fFuerza/dis2);//3, 9);
// else
// circles[i].get()->addAttractionPoint(ptF, ff*2.2*fFuerza/dis2);//4.0);
circles[i].get()->addAttractionPoint(ptF, ff*2.2*fFuerza/dis2);//4.0);
}
for(int i=0; i<boxes.size(); i++) {
float dis = ptF.distance(boxes[i].get()->getPosition());
float dis2 = dis*dis;//ptF.squareDistance(boxes[i].get()->getPosition());
// if(dis < minDis)
// if(dis2 < minDis2)
// boxes[i].get()->addAttractionPoint(ptF, ff*1.2*fFuerza/dis2);
// else
// boxes[i].get()->addRepulsionForce(ptF, ff*0.8*fFuerza/dis2);//4.0);
boxes[i].get()->addRepulsionForce(ptF, ff*0.9*fFuerza/dis2);//4.0);
}
}
else {
// Mouse Pressed
// Atrae boxes y repele circulos
for(int i=0; i<circles.size(); i++) {
// float dis = ptF.distance(circles[i].get()->getPosition());
float dis2 = ptF.squareDistance(circles[i].get()->getPosition());
// if(dis < minDis)
// if(dis2 < minDis2)
// circles[i].get()->addAttractionPoint(ptF, ff*1.2*fFuerza/dis2);//3, 9);
// else
circles[i].get()->addRepulsionForce(ptF, ff*0.8*fFuerza/dis2);//4.0);
}
for(int i=0; i<boxes.size(); i++) {
float dis = ptF.distance(boxes[i].get()->getPosition());
float dis2 = ptF.squareDistance(boxes[i].get()->getPosition());
// if(dis < minDis)
if(dis2 < minDis2)
// boxes[i].get()->addRepulsionForce(ptF, ff*1.4*fFuerza/dis);
// else
boxes[i].get()->addAttractionPoint(ptF, ff*2.2*fFuerza/dis2);//4.0);
}
}
}
}
示例2: getTriangleRadius
//-------------------------------------------------------------------
static float getTriangleRadius(ofVec2f v1, ofVec2f v2, ofVec2f v3) {
float a = v1.distance(v2);
float b = v2.distance(v3);
float c = v3.distance(v1);
float k = 0.5 * (a+b+c);
float r = sqrt( k * ((k-a)*(k-b)*(k-c)) ) / k;
return r;
}
示例3: getTriangleCenter
//-------------------------------------------------------------------
static ofVec2f getTriangleCenter(ofVec2f v1, ofVec2f v2, ofVec2f v3) {
float a = v2.distance(v3);
float b = v1.distance(v3);
float c = v1.distance(v2);
float d = a+b+c;
float ix = ((a * v1.x) + (b * v2.x) + (c * v3.x)) / d;
float iy = ((a * v1.y) + (b * v2.y) + (c * v3.y)) / d;
return ofVec2f(ix, iy);
}
示例4: GetControlPointAtPosition
int BSpline::GetControlPointAtPosition(ofVec2f position)
{
for (int i = 0; i < controlPoints.size(); ++i) {
if (position.distance(controlPoints[i]) < 10)
return i;
}
return -1;
}
示例5: checkAngle
bool TriangleBrush::checkAngle(ofVec2f p1, ofVec2f p2, ofVec2f p3){
float dist1 = p1.distance(p2);
float dist2 = p1.distance(p3);
if (dist2 < dist1) {
return true;
}else{
return false;
}
}
示例6: getNearestVertex
float getNearestVertex(const ofMesh& mesh, const ofVec2f& target, int& vertexIndex) {
float bestDistance = 0;
for(int i = 0; i < mesh.getNumVertices(); i++) {
float distance = target.distance(mesh.getVertex(i));
if(distance < bestDistance || i == 0) {
bestDistance = distance;
vertexIndex = i;
}
}
return bestDistance;
}
示例7: ofGetWidth
vector<ofVec2f> PyramidBrush::sortClosest(ofVec2f p, vector<ofVec2f> coords){
vector<ofVec2f> pos;
float maxDist = ofGetWidth();
int closestIndex = 0;
for (int i = 0; i < coords.size(); i++) {
float dist = p.distance(coords[i]);
if (dist < maxDist){
maxDist = dist;
pos.push_back(coords[i]);
}
}
return pos;
}
示例8: result
ofVec2f Simple3DTracker::_predictNextPosition(ofVec2f currentPosition, float* minCost)
{
int bestx = currentPosition.x, besty = currentPosition.y;
float bestcost = 9999999, cost, distance;
const float alpha = _weightedMatchingCoefficient;
if(!_template || !_tmp || !_tmp2)
return currentPosition;
// template matching
IplImage* haystack = _cameraImage();
cvMatchTemplate(haystack, _template->getCvImage(), _tmp2, CV_TM_CCOEFF);
cvNormalize(_tmp2, _tmp2, 1.0, 0.0, CV_MINMAX);
// find the best match
for(int y = 0; y < _tmp2->height; y++) {
const float *src = (const float*)(_tmp2->imageData + y * _tmp2->widthStep);
unsigned char *dst = (unsigned char*)(_tmp->getCvImage()->imageData + y * _tmp->getCvImage()->widthStep);
for(int x = 0; x < _tmp2->width; x++) {
dst[x] = (unsigned char)(src[x] * 255.0f);
distance = currentPosition.distance(ofVec2f(x, y));
if(distance <= _lookupRadius) {
cost = (alpha * (1.0f - src[x])) + ((1.0f - alpha) * distance / _lookupRadius);
if(cost <= bestcost) { // weighted matching
bestx = x;
besty = y;
bestcost = cost;
}
}
}
}
_tmp->flagImageChanged();
// get the resulting position...
ofVec2f result(bestx + _template->width/2, besty + _template->height/2);
// return the min cost?
if(minCost)
*minCost = bestcost;
// update the template?
if(result.distance(currentPosition) >= UPDATETPL_MINDIST)
_setTemplate(result);
// done!
return result;
}
示例9: select_point
bool select_point(ofVec2f f, ofVec2f t, float r)
{
if ( f.distance(t) < r ) return true;
else return false;
}
示例10: isPointOverCenter
bool Sphere::isPointOverCenter(ofVec2f p, float radiusMultiply)
{
return p.distance(center) < SphereTones::sphereRadius * radiusMultiply;
}
示例11: getDistanceToCenter
//----------------------------------
float PointGroup::getDistanceToCenter(ofVec2f _loc) {
return (_loc.distance(mCenter));
}
示例12: getIsPointInside
bool handle::getIsPointInside(ofVec2f t_mouse) {
return t_mouse.distance(m_posC) <= m_radius;
}
示例13: checkClick
int Neuron::checkClick(ofVec2f mouse) {
float dist = mouse.distance(loc);
if (dist < r) return ID;
else return -1;
}
示例14: isDistanceBigger
bool TriangleBrush::isDistanceBigger(ofVec2f a, ofVec2f b, float distance){
return a.distance(b) > distance? true : false;
}
示例15: makeLine
//--------------------------------------------------------------
void drawingCanvas::makeLine(ofVec2f mouse){
int intersect=0;
vector< ofPoint > points = myPolyline->getVertices();
int size = points.size();
if(mouse.distance(lastMouse) > 3){
//check for intersection first!!
if(size > 10){
//check lines on the ofPolyline
if(drawDummy==false){
for(int i=0; i< myPolyline->size()-2; i ++){
//only check if line is close to mouse
//if((points[i].x > mouse.x-6) && (points[i].x < mouse.x+6)){
// if((points[i].y > mouse.y-6) && (points[i].y < mouse.y+6)){
intersect = intersection(points[i],points[i+1],lastMouse,mouse);
if(intersect == 2){
//intersection found
i = myPolyline->size();//escape for loop
}
// }
//}
}
if(intersect == 0){
//no intersection
myPolyline->addVertex(mouse);
//fix offset of point since they are in in the "middle" of the screen
//they have to be where the slicing takes place
myPolyline2->addVertex(ofVec2f(mouse.x-posCanvas.x,mouse.y-posCanvas.y));
drawDummy = false;
}else if(intersect == 2){
//YES intersection
//draw the segment to the mouse but not saving it into the polyline
drawDummy = true;
myDummyLine = new ofPolyline();//////////////////////////////////////////////////////////////remember to dlete this *memory
myDummyLine->addVertex(points[points.size()-1]);
myDummyLine->addVertex(mouse);
//dummyA = points[points.size()-1];
//dummyB = mouse;
}
}else{
//do comparison wih dummyline, until there is no intersection with dummy line, there is no more adition to the real polyline
/*intersect = intersection(,lastMouse,mouse);*/
vector< ofPoint > pointsDummy = myDummyLine->getVertices();
for(int i=0; i< myPolyline->size()-2; i ++){
//only check if line is close to mouse
intersect = intersection(points[i],points[i+1],pointsDummy[0],pointsDummy[1]);
if(intersect == 2){
//intersection found
i = myPolyline->size();//escape for loop
}
}
if(intersect == 2){
//YES intersection
//draw the segment to the mouse but not saving it into the polyline
drawDummy = true;
myDummyLine->clear();
myDummyLine->addVertex(points[points.size()-1]);
myDummyLine->addVertex(mouse);
//dummyA = points[points.size()-1];
//dummyB = mouse;
}else{
//no intersection
//return to real polyline
drawDummy = false;
myDummyLine->clear();
}
}
}else{
//not looking for intersection
myPolyline->addVertex(mouse);
//fix offset of point since they are in in the "middle" of the screen
//they have to be where the slicing takes place
myPolyline2->addVertex(ofVec2f(mouse.x-posCanvas.x,mouse.y-posCanvas.y));
drawDummy = false;
}
}
}