void PMCone::createPoints( PMPointArray& points, const PMVector& end1, const PMVector& end2, double radius1, double radius2, int steps ) { double angle = ( 2.0 * M_PI ) / (double) steps; PMVector pointAt = end2 - end1; double pl = pointAt.abs( ); if( approxZero( pl ) ) pointAt = PMVector( 0.0, 1.0, 0.0 ); else pointAt /= pl; PMMatrix rotation = PMMatrix::rotation( pointAt, angle ); PMVector endPoint1 = pointAt.orthogonal( ); endPoint1 *= radius1; PMVector endPoint2 = pointAt.orthogonal( ); endPoint2 *= radius2; int i; for( i = 0; i < steps; i++ ) { points[i] = PMPoint( endPoint1 + end1 ); points[i + steps] = PMPoint( endPoint2 + end2 ); endPoint1 = rotation * endPoint1; endPoint2 = rotation * endPoint2; } }
void PMTorus::createPoints( PMPointArray& points, double minor_radius, double major_radius, int uStep, int vStep ) { double l_UradStep = ( 2.0 * M_PI ) / uStep; double l_VradStep = ( 2.0 * M_PI ) / vStep; double l_u = l_UradStep; int u, v; for( u = 0; u < uStep; ++u ) { double l_v = 0.0; double y = minor_radius * sin ( l_u ); double l_rcosu = major_radius + minor_radius * cos( l_u ); for( v = 0; v < vStep; ++v ) { double x = l_rcosu * cos( l_v ); double z = l_rcosu * sin( l_v ); points[u * vStep + v ] = PMPoint( x, y, z ); l_v = l_v + l_VradStep; } l_u = l_u + l_UradStep; } }
void PMSuperquadricEllipsoid::createPoints( PMPointArray& points, double e, double n, int uStep, int vStep ) { int u, v; int zi; int pbase = 0, pref = 0; if( e <= 0.001 ) e = 0.001; if( n <= 0.001 ) n = 0.001; double c2_e = 2.0 / e; double c2_n = 2.0 / n; double cn_2 = n / 2.0; double ce_2 = e / 2.0; double cn_e = n / e; // double ce_n = e / n; double z = 0.0, c = 0.0, a = 0.0, a2 = 0.0, x = 0.0, y = 0.0; double k = 0.0, k2 = 0.0, du = 0.0, dv = 0.0; PMPoint p; points[0] = PMPoint( 0, 0, 1 ); pbase++; for( zi = 0; zi < 2; zi++ ) { for( u = 0; u < uStep; u++ ) { du = ( double ) ( u + 1 ) / ( double ) uStep; if( zi == 1 ) du = 1.0 - du; k = tan( M_PI / 4.0 * pow( du, n < 1.0 ? n : sqrt( n ) ) ); k2 = 1 / ( pow( k, c2_n ) + 1 ); z = pow( k2, cn_2 ); if( zi == 1 ) z *= k; c = pow( 1 - pow( z, c2_n ), cn_e ); for( v = 0; v < ( vStep + 1 ); v++ ) { dv = ( double ) v / ( double ) vStep; a = tan( M_PI / 4.0 * pow( dv, e < 1.0 ? e : sqrt( e ) ) ); a2 = 1 + pow( a, c2_e ); x = pow( c / a2, ce_2 ); y = x * a; points[pbase+v] = PMPoint( x, y, z ); } // 1/8 pref = pbase + 2 * vStep; for( v = 0; v < vStep; v++, pref-- ) { p = points[pbase+v]; x = p[0]; p[0] = p[1]; p[1] = x; points[pref] = p; } // 1/4 pref = pbase + 4 * vStep; for( v = 0; v < ( 2 * vStep ); v++, pref-- ) { p = points[pbase+v]; p[0] = -p[0]; points[pref] = p; } // 1/2 pref = pbase + 8 * vStep - 1; for( v = 1; v < ( 4 * vStep ); v++, pref-- ) { p = points[pbase+v]; p[1] = -p[1]; points[pref] = p; } pbase += 8 * vStep; } } for( u = 0; u < ( uStep * 2 - 1 ); u++ ) { pbase = 1 + u * vStep * 8; pref = 1 + ( uStep * 4 - 2 - u ) * vStep * 8; for( v = 0; v < ( vStep * 8 ); v++, pref++ ) { p = points[pbase + v]; p[2] = -p[2]; points[pref] = p; } } points[ vStep * 8 * ( uStep * 4 - 1 ) + 1 ] = PMPoint( 0, 0, -1 ); }