package jhpro.engine3d;
public class MoebiusStrip {
public static FacetedObject create(int numSegs)
{
int numFacets = numSegs;
int numPoints = numSegs * 2;
int radius = 50;
double xr = (int)((double)radius * 1.2D);
double yr = (int)((double)radius * 0.80000000000000004D);
double width = 16D;
double halfWidth = width / 2D;
double radiansPerSeg = 6.2831853071795862D / (double)(float)numSegs;
FacetedObject fo = new FacetedObject(numPoints, numFacets, 4);
for(int i = 0; i < numSegs; i++)
{
double theta = (double)i * radiansPerSeg;
double x;
double z;
if(i < numSegs / 2)
{
x = halfWidth * Math.sin(theta);
z = halfWidth * Math.cos(theta);
} else
{
x = 0.0D;
z = -halfWidth;
}
double xm = (xr - x) * Math.cos(theta);
double xp = (xr + x) * Math.cos(theta);
double ym = (yr - x) * Math.sin(theta);
double yp = (yr + x) * Math.sin(theta);
fo.setPointData(xm, ym, z);
fo.setPointData(xp, yp, -z);
}
int indexPattern[] = {
0, 2, 3, 1
};
int indexPatternEnd[] = {
numPoints - 2, 1, 0, numPoints - 1
};
for(int i = 0; i < numPoints; i += 2)
{
for(int j = 0; j < 4; j++)
fo.setVectorIndex(i >= numPoints - 2 ? indexPatternEnd[j] : i + indexPattern[j]);
}
return fo;
}
}
Ads help maintain this website.