Ejemplo n.º 1
0
int main(int argc, char* argv[])
{
    cout << "Enter 3 sides of triangle." << endl;

    string commandLine;
    getline(cin, commandLine);

    while (!cin.eof())
    {
        array<double, 3> args;

        try
        {
            args = GetArguments(commandLine);
            CTriangle triangle = CTriangle(args[0], args[1], args[2]);

            cout << "S = " << triangle.GetArea() << ", P = " << triangle.GetPerimeter() << endl;
        }
        catch (exception &e)
        {
            cout << e.what() << endl;
        }

        getline(cin, commandLine);
    }

    return 0;
}
Ejemplo n.º 2
0
bool CEditableElementCommon::intersect(const NLMISC::CVector &rayStart, const NLMISC::CVector &rayEnd, NLMISC::CVector &rayHit, const NLMISC::CMatrix &mat)
{
	//return true;
	//CMatrix mat = mesh()->getMatrix();
	CMatrix imat = mat;
	imat.invert();
	//rayEnd = imat * rayEnd;
	//rayStart = imat * rayStart;
	
	uint32 i;
	for(i = 0; i<NbFaces; i++)
	{
		CTriangle tri;
		tri.V0 = mat * Vertices[Indices[i*3+0]];
		tri.V1 = mat * Vertices[Indices[i*3+1]];
		tri.V2 = mat * Vertices[Indices[i*3+2]];
		
		CPlane p;
		p.make(tri.V0,tri.V1,tri.V2);
		CVector hit;
		bool res = tri.intersect(rayStart,rayEnd,hit,p);
		if(res)
		{
			rayHit = hit;
			return true;
		}
	}
	
	
	return false;
}
Ejemplo n.º 3
0
int main() {
  CRectangle rect;
  CTriangle trgl;
  rect.set_values(4,5);
  trgl.set_values(4,5);
  cout << rect.area() << endl;
  cout << trgl.area() << endl;
  return 0;
}
Ejemplo n.º 4
0
int main(){
	CRectangle rect;
	CTriangle trgl;
	rect.set_values(4, 5);
	trgl.set_values(4, 5);
	rect.output(rect.area());
	trgl.output(trgl.area());
	return 0;
}
Ejemplo n.º 5
0
int main(){
  CRectangle rect;
  CTriangle trgl;
  CPolygon*ppoly1 = &rect;
  CPolygon&ppoly2 = &trgl;
  ppoly1->set_values (4,5);
  ppoly2->set_values (4,5);
  cout << rect.area() << endl;
  cout << trgl.area() << endl;
  return 0;
}
void testFunction ()
{
	int a,b;
	CRectangle rect;
	CTriangle trgl;
	CPolygon * ppoly1 = &rect;
	CPolygon * ppoly2 = &trgl;
	ppoly1->set_values (4,5);
	ppoly2->set_values (4,5);
	a = rect.area();
	b = trgl.area();
}
Ejemplo n.º 7
0
BOOL CConvexHullGenerator::NotContained(SFloat3* psPosition)
{
	SFreeListIterator	sIter;
	CTriangle*			pcTriangle;

	pcTriangle = (CExtremeTriangle*)mcTriangles.StartIteration(&sIter);
	while (pcTriangle)
	{
		if (pcTriangle->NotContains(psPosition))
		{
			return TRUE;
		}
		pcTriangle = (CExtremeTriangle*)mcTriangles.Iterate(&sIter);
	}
	return FALSE;
}
Ejemplo n.º 8
0
int main () {
	CPolygon* polygons[4];
	
	polygons[0] = new CRectangle(20,30);
	polygons[1] = new CTriangle(20,25);
	polygons[2] = new CCircle(25,25);
	polygons[3] = new CSquare(18,18);
	
	for(int i = 0; i < 4; i++)
	{
		CTriangle* trin = dynamic_cast <CTriangle *> (polygons[i]);
		if (trin != 0)
		{
			trin->set_values(10, 10);
			assert(trin->area() != 50);
		}
		
		CCircle* circ = dynamic_cast <CCircle *> (polygons[i]);
		if (circ != 0)
		{
			circ->set_values(10, 10);
			assert(circ->area() != 78);
		}
		
		CSquare* sqrr = dynamic_cast <CSquare *> (polygons[i]);
		if (sqrr != 0)
		{
			sqrr->set_values(10, 10);
			assert(sqrr->area() != 100);
		}
		
		CRectangle* rect = dynamic_cast <CRectangle *> (polygons[i]);
		if (rect != 0)
		{
			rect->set_values(10, 20);
			assert(rect->area() != 200);
		}
		
	}
/*
*/

  return 0;
}
Ejemplo n.º 9
0
int main()
{
	// Here we make an instances of our "specific shape classes"
	CTriangle triangle;
	CSquare square;

	// **Note -- Every time we make an instance of any of CTriangle or CSquare,
	// that instance will have a hidden member variable called a vtable pointer (vptr).
	// This member variable will point to the class's vtable the object was created from.

	// Notice this function takes a CShape&, but remember CTriangle was derived from
	// CShape, so it is a "CShape".  Also notice WE DO NOT have to typecast.
	Draw(triangle); // This should draw a triangle to the screen

	Draw(square);   // This should draw a square to the screen

	// Again, this should draw a triangle to the screen
	triangle.draw();

	return EXIT_SUCCESS; // I feel good about this program ending :)

}
Ejemplo n.º 10
0
void ConvertTrianglesToPolygons(CArrayTrianglePtr* papcTriangles, CArrayPolygons* pacPolygons)
{
	int				i;
	CTriangle*		pcTriangle;
	int				j;
	CTriangle*		pcTriangleOther;
	CPolygon*		pcPolygon;

	for (i = 0; i < papcTriangles->NumElements(); i++)
	{
		pcTriangle = *papcTriangles->Get(i);
		pcPolygon = pacPolygons->Add();
		pcPolygon->Init();
		pcPolygon->AddTriangle(pcTriangle);

		for (j = i+1; j < papcTriangles->NumElements(); j++)
		{
			pcTriangleOther = *papcTriangles->Get(j);

			if (pcTriangle->Coplanar(pcTriangleOther))
			{
				pcPolygon->AddTriangle(pcTriangleOther);
				papcTriangles->RemoveAt(j);
				j--;
			}
		}
	}

	//You still need to check that the coplanar polygons are contiguous.

	//for (i = 0; i < pacPolygons->NumElements(); i++)
	//{
	//	pcPolygon = pacPolygons->Get(i);
	//	pcPolygon->Dump();
	//}
}
Ejemplo n.º 11
0
void CGetShapeInfo::Visit(CTriangle& shape)
{
	m_val = "TRIANGLE: P=" + shape.GetPerimeter().ToString() + "; S=" + shape.GetSquare().ToString();
}