Ejemplo n.º 1
0
AxialBox EncloseABox ( Cylinder const & C )
{
	Vector center = C.getCenter();

	Vector extent( C.getExtentX(), C.getExtentY(), C.getExtentZ() );

	return AxialBox(center-extent,center+extent);
}
Ejemplo n.º 2
0
Sphere EncloseSphere ( Cylinder const & shape )
{
	float x = shape.getExtentX();
	float y = shape.getExtentY();

    float radius = sqrt( x*x + y*y );

    return Sphere( shape.getCenter(), radius );
}
Ejemplo n.º 3
0
C3DModel CTriangulator<Real, Cylinder<Real> >::Triangulate(const Cylinder<Real> &pShape)
{

  Vector3<Real> center  = pShape.getCenter();
  Vector3<Real> u       = pShape.getU();
  Real height2           = pShape.getHalfLength();
  Real rad               = pShape.getRadius();

  C3DModel model;

  std::vector<Vector3<Real> > vVertices;
  std::vector<TriFace>         vFaces;

  int verticalsegments = 2;
  int pointsoncircle   = 24;

  Real dalpha = 2.0 * CMath<Real>::SYS_PI/(Real)pointsoncircle;

  Vector3<Real> vTop    = center + (height2 * u);
  Vector3<Real> vBottom = center - (height2 * u);
  vVertices.push_back(vTop);

  Real dheight = (2.0 * height2)/Real(verticalsegments+1);
  Real currentheight = center.z + height2;
  Real alpha = 0.0;

  //create the vertices
  for(int j=0;j<(verticalsegments+2);j++)
  {
    for(int i=0;i<pointsoncircle;i++)
    {
      Vector3<Real> vNext=pShape.eval(alpha);
      vNext.z = currentheight;
      vVertices.push_back(vNext);
      alpha+=dalpha;
    }
    alpha=0.0;
    currentheight-=dheight;
  }

  vVertices.push_back(vBottom);

  //add the top triangle fan
  for(int i=0;i<pointsoncircle;i++)
  {
    int verts[3];
    verts[0]=0;
    verts[1]=1+i;
    verts[2]=1+(i+1)%pointsoncircle;
    TriFace face(verts);
    vFaces.push_back(face);
  }

  //add the body of the cylinder
  int index = 1;
  for(int i=0;i<verticalsegments+1;i++)
  {
	  int index=1+i*pointsoncircle;
	  for(int j=0;j<pointsoncircle;j++)
	  {
	    int verts[3];
	    verts[0]=index+j;
	    verts[1]=index+pointsoncircle+j;
	    verts[2]=index+(j+1)%pointsoncircle;

	    TriFace face1(verts);
	    vFaces.push_back(face1);
	    verts[0]=index+(j+1)%pointsoncircle;
	    verts[1]=index+pointsoncircle+j;
	    verts[2]=index+pointsoncircle+(j+1)%pointsoncircle;
	    TriFace face2(verts);
	    vFaces.push_back(face2);
	  }
  }//end for i

  int ilast=vVertices.size()-1;
  int ilastrow=ilast-pointsoncircle;
  //add lower triangle fan
  for(int i=0;i<pointsoncircle;i++)
  {
	int verts[3];
	verts[0]=ilast;
	verts[1]=ilastrow+(i+1)%pointsoncircle;
	verts[2]=ilastrow+i;
	TriFace face(verts);
	vFaces.push_back(face);
  }

  model.CreateFrom(vVertices,vFaces);

  return model;

}