Esempio n. 1
0
Position RandomTriangleOfferStrategy::propose(EdgeworthSituation const& situation, URNG& rng) const
{
    Position const p0 = situation.getFixPoint();
    Position const p1 = situation.calculateCurve1ParetoIntersection();
    Position const p2 = situation.calculateCurve2ParetoIntersection();

    std::uniform_real_distribution<double> udist(0.0, 1.0);

    //we pick a point as if in a paralelogram for sake of uniformity
    auto const v01 = (p1 - p0);
    auto const v02 = (p2 - p0);
    double const factor1 = udist(rng);
    double const factor2 = udist(rng);
    Position px = p0 + v01*factor1 + v02*factor2;

    //if the point falls in the wrong half
    //  then we do point reflection around p1-p2 side's midde point
    //  to end up in the desired half
    if (!isPointInTriangle(p0, p1, p2, px)) {
        auto origo = p1 + (p2 - p1) * 0.5;
        px = px + (origo - px) * 2.0;
    }
    //debugShowPoint(px);
    return px;
}
int CalibrationUtils::findTriangleWithin(vector2df pt)
{
	for(int t = 0; t < GRID_INDICES; t += 3)
	{
		if(isPointInTriangle(pt, cameraPoints[triangles[t]], cameraPoints[triangles[t+1]], cameraPoints[triangles[t+2]]) )
			return t;
	}
	return -1;
}
Esempio n. 3
0
int ofxMultiplexer::findTriangleWithin(vector2df pt,vector2df* screenPoints,int* triangles)
{
	for(int t = 0; t < actualCalibrationGridWidth * actualCalibrationGridHeight * 6; t += 3)
	{
		if(isPointInTriangle(pt, screenPoints[triangles[t]], screenPoints[triangles[t+1]], screenPoints[triangles[t+2]]) )
			return t;
	}
	return -1;
}
bool EarClippingTriangulation::isEar(size_t v0, size_t v1, size_t v2) const
{
	for (std::list<size_t>::const_iterator it (_vertex_list.begin ());
	     it != _vertex_list.end(); ++it)
		if (*it != v0 && *it != v1 && *it != v2)
			if (isPointInTriangle (_pnts[*it], _pnts[v0], _pnts[v1], _pnts[v2]))
				return false;

	return true;
}
Esempio n. 5
0
/**
 * Prueft ob der Strahl ray dieses Dreieck schneidet.
 * Gibt es einen Schnittpunkt verweist result darauf.
 * @param ray Zu testender Strahl
 * @param result Hier wird bei Existenz der Schnittpunkt abgelegt
 */
bool Triangle::intersectsRay(const Ray &ray, Vector3D *result) const
{
    bool bResult = false;

    // Schneidet der Strahl die Ebene des Dreiecks?
    // Schnittpunkt des Strahls mit Ebene des Dreiecks
    Vector3D i;
    if (rayIntersectsPlane(ray, *this, &i))
		// Liegt Schnittpunkt zur Ebene im Dreieck?
		if (bResult = isPointInTriangle(i))
			*result = i;

    return bResult;
}
Esempio n. 6
0
double RTriangle::getDistanceTo(const RVector& point, bool limited) const {

    RVector normal = getNormal();
    double d = getD();
    double distance = (normal.x * point.x + normal.y * point.y + normal.z
            * point.z + d) / (normal.getMagnitude());

    if (!limited
            || isPointInTriangle(point - normal.getUnitVector() * distance)) {
        return distance;
    }

    return RMAXDOUBLE;
}
Esempio n. 7
0
int calibrationB::findTriangleWithin(vector2df pt)
{
	int t;

	for(t=0; t<GRID_INDICES; t+=3)
	{
		if( isPointInTriangle(pt, cameraPoints[triangles[t]], cameraPoints[triangles[t+1]], cameraPoints[triangles[t+2]]) )
		{
			return t;
		}
	}

	return -1;
}
Esempio n. 8
0
//--------------------------------------------------------------
meshFaceSelectorResult* meshFaceSelector::select(const vector<ofMeshFaceApparel*>& meshFaces, const ofCamera& cam, const ofVec2f& point)
{
	ofVec3f 			pointWorld = cam.screenToWorld(ofVec3f(point.x, point.y, 0.0));
    ofRay 				ray(cam.getPosition(),pointWorld - cam.getPosition());
	ofMeshFaceApparel* 	pFace;
	ofPlane				facePlane;
	ofVec3f				faceNormal, faceNormalCam;
	ofVec3f 			pointOnPlane;
	ofMeshFace*			pMeshFace = 0;
	
	result.face = 0;
	result.faceIndex = -1;
	result.vertex = 0;

	for (int i=0; i<meshFaces.size(); i++)
	{
		pFace 		= meshFaces[i];
		faceNormal 	= pFace->getFaceNormal();
		
		facePlane.setCenter(pFace->getVertex(0));
		facePlane.setNormal(faceNormal);
		
		// Intersection with plane
	   	if ( facePlane.intersect(ray,pointOnPlane) )
		{
			// Point in triangle ?
			if ( isPointInTriangle(pFace->getVertex(0),pFace->getVertex(1),pFace->getVertex(2), pointOnPlane) )
			{
				ofVec3f dir = pointOnPlane - cam.getPosition();

				if (dir.dot(faceNormal)<0.0f)
				{
					result.face = pFace;
					result.faceIndex = i;
					
					onMeshFaceSelected(pFace, pointOnPlane);
					break;
				}
			}
		}
	}
	
	return &result;
}
Esempio n. 9
0
bool isEdgeTriangleIntersection(const MVector3 & origin, const MVector3 & dest, const MVector3 & a, const MVector3 & b, const MVector3 & c, const MVector3 & normal, MVector3 * point)
{
	MVector3 iPoint;

	if(isEdgePlaneIntersection(origin, dest, a, normal, &iPoint))
	{
		if(isPointInTriangle(iPoint, a, b, c, normal))
		{
			if(! point)
				return true;

			point->x = iPoint.x;
			point->y = iPoint.y;
			point->z = iPoint.z;
			return true;
		}
	}

	return false;
}
Esempio n. 10
0
bool FloatQuad::containsPoint(const FloatPoint& p) const
{
    return isPointInTriangle(p, m_p1, m_p2, m_p3) || isPointInTriangle(p, m_p1, m_p3, m_p4);
} 
Esempio n. 11
0
PolygonGroup *Tesselator::tesselatePolygon(const Polygon *pPolygon)
{

	ASSERT(pPolygon->vertexCount() > 2, "This is not a polygon!");

	PolygonGroup *pGroup = new PolygonGroup();

	const std::vector<Vec> &vertices = pPolygon->vertices();
	std::vector<int> poly;

	for(unsigned int i = 0; i < vertices.size(); ++i)
		poly.push_back(i);

	while(poly.size() > 2)
	{
		//INFO("-->%u", poly.size());
		for(unsigned int i = 0; i < poly.size(); ++i)
		{
		//	INFO("%u", i);
			unsigned int i1 = i;
			unsigned int i2 = (i + 1) % poly.size();
			unsigned int i3 = (i + 2) % poly.size();

			const Vec &v1 = vertices.at(poly.at(i1));
			const Vec &v2 = vertices.at(poly.at(i2));
			const Vec &v3 = vertices.at(poly.at(i3));

		//	INFO("\na %f %f", v1.x(), v1.y());
		//	INFO("b %f %f", v2.x(), v2.y());
		//	INFO("c %f %f", v3.x(), v3.y());

			if(isVertexReflex(v1, v2, v3))
				continue;

		//	INFO("isnt reflex");

			bool ear = true;

			for(unsigned int j = 0; j < poly.size(); ++j)
			{
				if(j != i1 && j != i2 && j != i3)
				{
					if(isPointInTriangle(vertices.at(poly.at(j)), v1, v2, v3))
					{
						ear = false;
						break;
					}
				}
			}

			if(ear)
			{
				Polygon *pPoly = new Polygon();

				pPoly->addVertex(v1);
				pPoly->addVertex(v2);
				pPoly->addVertex(v3);

				pGroup->addPolygon(pPoly);

				poly.erase(poly.begin() + i2);

				break;
			}
		}
	}



	return pGroup;
}
Esempio n. 12
0
bool RTriangle::isPointInQuadrant(const RVector& ip) const {
    return isPointInTriangle(ip, true);
}
Esempio n. 13
0
Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VEC3& Ta,  const VEC3& Tb, const VEC3& Tc, VEC3& Inter)
{
	Inclusion inc = isPointInTriangle(P,Ta,Tb,Tc) ;
	VEC3 N = Ta ^ Tb ;

	switch(inc)
	{
		case FACE_INCLUSION :
			Inter = P ;
			return FACE_INTERSECTION ;
		case EDGE_INCLUSION :
			Inter = P ;
			return EDGE_INTERSECTION ;
		case VERTEX_INCLUSION :
			Inter = P ;
			return VERTEX_INTERSECTION ;
		default : //NO_INCLUSION : test if ray enters the triangle
			VEC3 P2 = P + Dir ;
			Orientation2D oA = testOrientation2D(Ta, P, P2, N) ;
			Orientation2D oB = testOrientation2D(Tb, P, P2, N) ;
			Orientation2D oC = testOrientation2D(Tc, P, P2, N) ;

			if(oA == oB && oB == oC)
				return NO_INTERSECTION ;

			Orientation2D oPBC = testOrientation2D(P,Tb,Tc,N) ;
			if(oPBC == LEFT)  // same side of A, test edge AC and AB
			{
				if(oA == LEFT)
				{
					if(oB == ALIGNED)
					{
						Inter = Tb ;
						return VERTEX_INTERSECTION ;
					}
					//inter with AB
//					CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AB" << CGoGNendl ;
					return EDGE_INTERSECTION ;
				}
				if(oA == ALIGNED)
				{
					Inter = Ta ;
					return VERTEX_INTERSECTION ;
				}
				if(oC == ALIGNED)
				{
					Inter = Tc ;
					return VERTEX_INTERSECTION ;
				}
				//inter with AC
//				CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AC" << CGoGNendl ;
				return EDGE_INTERSECTION ;
			}
			if(oPBC == RIGHT) // same side of BC, test this edge
			{
				if(oB == ALIGNED)
				{
					Inter = Tb ;
					return VERTEX_INTERSECTION ;
				}
				if(oC == ALIGNED)
				{
					Inter = Tc ;
					return VERTEX_INTERSECTION ;
				}
				//inter with BC
//				CGoGNout << __FILE__ << " TODO compute edge coplanar intersection BC" << CGoGNendl ;
				return EDGE_INTERSECTION ;
			}

			//aligned with BC
			//possibly colliding with edge AB or AC
			Orientation2D oPAB = testOrientation2D(P,Ta,Tb,N) ;
			if(oPAB == RIGHT) //possibly colliding with edge AB
			{
				if(oA == ALIGNED)
				{
					Inter = Ta ;
					return VERTEX_INTERSECTION ;
				}
				//inter with AB
//				CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AB" << CGoGNendl ;
				return EDGE_INTERSECTION ;
			}
			if(oPAB == ALIGNED)
			{
				Inter = Tb ;
				return VERTEX_INTERSECTION ;
			}
			//possibly colliding with edge AC
			else if(oC == ALIGNED)
			{
				Inter = Tc ;
				return VERTEX_INTERSECTION ;
			}
			else if(oA == ALIGNED)
			{
				Inter = Ta ;
				return VERTEX_INTERSECTION ;
			}
			//inter with AC
//			CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AC" << CGoGNendl ;
			return EDGE_INTERSECTION ;
	}
}