Example #1
0
int main(void){
	int c, r, i, j;
	double xmin, ymin, xmax, ymax,x0,y0,x1, y1, x2, y2, x3, y3;
	scanf("%d%d%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&r,&c,&xmin,&ymin,&xmax,&ymax,&x1,&y1,&x2,&y2,&x3,&y3);
	
	printf("+");
	for(i=1; i<=c; i++){
		printf ("-");
	}
	printf ("+\n");
 
	for (j=0; j<r; j++){ 
		printf("|");
		for(i=0; i<c; i++){
			x0=(((xmax-xmin)/(c-1))*i)+xmin;
			y0=(((ymax-ymin)/(r-1))*(r-j-1))+ymin;

			if (inTriangle(x0,y0,x1,y1,x2,y2,x3,y3)){ 
				printf("*");
			}
			else {
				printf(" ");
			}    
		}
		printf("|\n");
	}	
  
	printf("+");
	for(i=1; i<=c; i++){
		printf ("-");
	}
	printf ("+\n");
	 
	return 0;
}
// Determina se no ponto p do polígono o triangulo formado com os vértices vizinhos é uma orelha
int checkEar(list<int> & currPoly, list<int>::iterator & pIterator, const vector<Point2D> & p){
	// Obtém ponto anterior a p no polígono atual
	list<int>::iterator prevIterator = getPrevIterator(currPoly, pIterator);
	// Obtém ponto seguinte a p no polígono atual
	list<int>::iterator nextIterator = getNextIterator(currPoly, pIterator);

	// Determina índice dos pontos do triângulo do teste de orelha
	int p0 = *prevIterator;
	int p1 = *pIterator;
	int p2 = *nextIterator;

	// Se p2 está a direita de p0p1 então a diagonal p0p2 é externa a currPoly, portanto não é uma orelha
	if(!isLeft(p[p0], p[p1], p[p2]))
		return 0;

	// Determina se algum ponto do polígono diferente de p0, p1 e p2 é interno ao triângulo formado por estes pontos
	list<int>::iterator currIterator = getNextIterator(currPoly, nextIterator);
	while(currIterator != prevIterator){
		int currP = *currIterator;
		// Se o ponto atual está dentro do triângulo p0p1p2 então o mesmo não é uma orelha
		if(inTriangle(p[p0], p[p1], p[p2], p[currP])){
			return 0;
		}
		currIterator = getNextIterator(currPoly, currIterator);
	}

	// Se não existiu nenhum ponto dentro do triầngulo p0p1p2 então o mesmo é uma orelha
	return 1;
}
Example #3
0
Vector3D LightShadeModel::calcPhongNormal(Vector3D pos, Model *m, UINT face_id){
	UINT* vList = m->mesh->m_pFace[face_id].m_piVertex;

	Vector3D alpha(0,0,0);
	if (!inTriangle(m->mesh->m_pVertex[vList[0]].m_vPosition,
				    m->mesh->m_pVertex[vList[1]].m_vPosition,
					m->mesh->m_pVertex[vList[2]].m_vPosition,
					pos, alpha)){
		return Vector3D(0,0,0);
	}
	Vector3D norm(0,0,0);
	norm += m->mesh->m_pVertex[vList[0]].m_vNormal * alpha.x;
	norm += m->mesh->m_pVertex[vList[1]].m_vNormal * alpha.y;
	norm += m->mesh->m_pVertex[vList[2]].m_vNormal * alpha.z;
	return norm;
}
Example #4
0
float EarTriangulation<PFP>::computeEarInit(Dart d, const typename PFP::VEC3& normalPoly, float& val)
{
	typedef typename PFP::VEC3 VEC3 ;

	Dart e =  m_map.phi1(d);
	Dart f =  m_map.phi1(e);

	const VEC3& Ta = m_position[e];
	const VEC3& Tb = m_position[f];
	const VEC3& Tc = m_position[d];

	VEC3 v1 = Tc-Ta;
	VEC3 v2 = Tb-Ta;
	v1.normalize();
	v2.normalize();

//	val = 1.0f - (v1*v2);
	val = acos(v1*v2) / (M_PI/2.0f);

	VEC3 vn = v1^v2;
	if (vn*normalPoly > 0.0f)
		val = 10.0f - val; 		// not an ears  (concave, store at the end for optimized use for intersections)

	if (val>5.0f)
		return 0.0f;

	//INTERSECTION
	f =  m_map.phi1(f);
	while (f != d)
	{
		if (inTriangle(m_position[f], normalPoly,Tb,Tc,Ta))
		{
			val = 5.0f;
			return 0.0f;
		}
		f =  m_map.phi1(f);
	}

	return (Tb-Tc).norm2();
}
Example #5
0
CIntersectionInfo CTriangle::GetIntersection	(CRay ray)
{
	CPoint3D ptNoIntersection (0.0f, 0.0f, 0.0f, 0.0f);	// no intersection by default
	CPoint3D ptOfIntersection;
	CIntersectionInfo hitInfo;

	/***************************************************************
	STRATEGY:

	There are two major steps when trying to find the point of 
	intersection of a ray with a triangle, first to see if the ray
	intersects the plane of the triangle and then to see if the point
	on the plane that the ray intersects with lies within the triangle.

	So:
	1. Find the point of intersection on the triangle plane.
	2. Check if this point lies insdie the plane or not.
	3. Set the information into the hitInfo object.
	4. Return the hitInfo object.
	***************************************************************/

	// 1.
	ptOfIntersection = PlaneIntersect(ray);

	// 2.
	if ( !inTriangle(ptOfIntersection) || ptOfIntersection.AtInfinity()) {

		return hitInfo;
	}

	// 3.
	hitInfo.SetPointOfIntersection (ptOfIntersection);
	hitInfo.SetNormal (GetNormalAt(ptOfIntersection));
	hitInfo.SetColor(objColor);
	hitInfo.SetTexCoords (GetTexCoords(ptOfIntersection));

	// 4.
	return hitInfo;
}
Example #6
0
void EarTriangulation<PFP>::recompute2Ears( Dart d, const typename PFP::VEC3& normalPoly, bool convex)
{
	typedef typename PFP::VEC3 VEC3 ;

	Dart d2 = m_map.phi_1(d);
	Dart d_p = m_map.phi_1(d2);
	Dart d_n = m_map.phi1(d);

	const VEC3& Ta = m_position[d2];
	const VEC3& Tb = m_position[d];
	const VEC3& Tc = m_position[d_p];
	const VEC3& Td = m_position[d_n];

	// compute angle
	VEC3 v1= Tb - Ta;
	VEC3 v2= Tc - Ta;
	VEC3 v3= Td - Tb;

	v1.normalize();
	v2.normalize();
	v3.normalize();

//	float dotpr1 = 1.0f - (v1*v2);
//	float dotpr2 = 1.0f + (v1*v3);
	float dotpr1 = acos(v1*v2) / (M_PI/2.0f);
	float dotpr2 = acos(-(v1*v3)) / (M_PI/2.0f);

	if (!convex)	// if convex no need to test if vertex is an ear (yes)
	{
		VEC3 nv1 = v1^v2;
		VEC3 nv2 = v1^v3;

		if (nv1*normalPoly < 0.0)
			dotpr1 = 10.0f - dotpr1;// not an ears  (concave)
		if (nv2*normalPoly < 0.0)
			dotpr2 = 10.0f - dotpr2;// not an ears  (concave)

		bool finished = (dotpr1>=5.0f) && (dotpr2>=5.0f);
		for (typename VPMS::reverse_iterator it = m_ears.rbegin(); (!finished)&&(it != m_ears.rend())&&(it->angle > 5.0f); ++it)
		{
			Dart dx = it->dart;
			const VEC3& P = m_position[dx];

			if ((dotpr1 < 5.0f) && (d != d_p))
				if (inTriangle(P, normalPoly,Tb,Tc,Ta))
					dotpr1 = 5.0f;// not an ears !

			if ((dotpr2 < 5.0f) && (d != d_n) )
				if (inTriangle(P, normalPoly,Td,Ta,Tb))
					dotpr2 = 5.0f;// not an ears !

			finished = ((dotpr1 >= 5.0f)&&(dotpr2 >= 5.0f));
		}
	}

	float length = (Tb-Tc).norm2();
	m_dartEars[d2] = m_ears.insert(VertexPoly(d2,dotpr1,length));

	length = (Td-Ta).norm2();
	m_dartEars[d] = m_ears.insert(VertexPoly(d,dotpr2,length));
}
bool Triangle::inTriangle(Node* n){
	return inTriangle(n->getPos());
}
bool Triangle::inTriangle(Node n){
	return inTriangle(n.getPos());
}