//######################### MAKE SMOOTH TUBE ###################### void Mesh::makeSmoothTube(FuncPtr spineX, FuncPtr spineY, FuncPtr spineZ, double tMax) { // make tube: wrap polygon about spine int numSpinePts = 200; int numSlices = 12; // # vrtices in polygon float radius = 1.0; float fractForInnerOuterRadii = 0.4f; // use inner-outer radii n-gon for polygon //---------------------------- make space for lists ----------------- numVerts = numSlices * numSpinePts; // total # vertices in mesh numFaces = numSlices * (numSpinePts - 1); // total # faces in mesh numNorms = numVerts; pt = new Point3[numVerts]; assert(pt != NULL); // make space for the lists face = new Face[numFaces]; assert(face != NULL); norm = new Vector3[numNorms]; assert(norm != NULL); //make polygon that wraps spine: Point2 *p = new Point2[numSlices]; assert(p);// place for polygon that wraps float ang = 0, delAng = TWOPI / numSlices; for (int j = 0; j < numSlices; j++, ang += delAng) // numSlices should be even { float rad = radius; //if(j%2) rad = fractForInnerOuterRadii * radius; //alternating radius p[j].x = rad * cos(ang); p[j].y = rad * sin(ang); } double t = 0, delT, eps = 0.0001; delT = tMax / (numSpinePts - 1); int last = -1; // loop over values of t for different spine segments for (int k = 0; k < numSpinePts; k++, t += delT) // for each spine point.. { Point3 spine(spineX(t), spineY(t), spineZ(t)); //make Frenet frame at spine points: Vector3 tangent, spinePrimePrime, B, N; //do tangent with numerical derivative double xderiv = (spineX(t + eps) - spineX(t - eps)) / (2 * eps); double yderiv = (spineY(t + eps) - spineY(t - eps)) / (2 * eps); double zderiv = (spineZ(t + eps) - spineZ(t - eps)) / (2 * eps); tangent.set(xderiv, yderiv, zderiv); tangent.normalize(); // second differences for the acceleration double xDoublePrime = (spineX(t - eps) - 2 * spineX(t) + spineX(t + eps)) / (eps*eps); double yDoublePrime = (spineY(t - eps) - 2 * spineY(t) + spineY(t + eps)) / (eps*eps); double zDoublePrime = (spineZ(t - eps) - 2 * spineZ(t) + spineZ(t + eps)) / (eps*eps); spinePrimePrime.set(xDoublePrime, yDoublePrime, zDoublePrime); B = tangent.cross(spinePrimePrime); B.normalize(); N = B.cross(tangent); N.normalize(); checkOrthogVects(tangent, B, N); // are tangent, B, and n orthonormal? //compute vertex list for (int j = 0; j < numSlices; j++) { Vector3 V(p[j].x * B.x + p[j].y * N.x, // construct new vector p[j].x * B.y + p[j].y * N.y, p[j].x * B.z + p[j].y * N.z); pt[++last].set(spine.x + V.x, spine.y + V.y, spine.z + V.z); norm[last].set(V.x, V.y, V.z); norm[last].normalize(); } // end: for each polygon vertex at this spine point } // end: for each spine segment // ----------------- make face lists -------------------- int ind = -1; for (int spinePt = 0; spinePt < numSpinePts - 1; spinePt++) { for (int f = 0; f < numSlices; f++) // for each face in this segment { face[++ind].nVerts = 4; face[ind].vert = new VertexID[4]; assert(face[ind].vert != NULL); int i0 = spinePt * numSlices + f; // first index of the vert in this face int i1 = (f == numSlices - 1) ? spinePt * numSlices : (i0 + 1); int i2 = i1 + numSlices; int i3 = i0 + numSlices; // last index of the vert in this face face[ind].vert[0].vertIndex = face[ind].vert[0].normIndex = i0; face[ind].vert[1].vertIndex = face[ind].vert[1].normIndex = i1; face[ind].vert[2].vertIndex = face[ind].vert[2].normIndex = i2; face[ind].vert[3].vertIndex = face[ind].vert[3].normIndex = i3; } // end: for each face in this segment } // end: for each spine segment - building face and normal lists } // end: makeTube()
int main() { std::cout << "LUL" << std::endl; { BST<int> bst({3}); // 3 } { BST<int> bst({3, 4}); // 3 | // \ | // 4 | } { BST<int> bst({3, 4, 1}); // 3 | // / \ | // 1 4 | } { BST<int> bst({3, 4, 1, 2}); // 3 | // / \ | // 1 4 | // \ | // 2 | } { BST<int> bst({3,4,1,2,7}); // 3 | // / \ | // 1 4 | // \ \ | // 2 7 | std::cout << bst << std::endl; std::cout << bst.height() << std::endl; } /* BST<int> bst({3,4,1,2,7,3}); // 3 | // / \ | // 1 4 | // \ \ | // 2 7 | // \ | // 3 | // // */ std::vector<int> temp; int sign = 1; for (int i = 0; i < 1000; ++i) { sign *= -1; temp.push_back(i * sign); } BST<int> bst(temp.begin(), temp.end()); std::cout << bst << std::endl; // prints 1 2 3 3 4 7 std::cout << bst.size() << std::endl; //prints 6 std::cout << bst.min() << std::endl; // prints 1 std::cout << bst.max() << std::endl; // prints 7 std::cout << bst.height() << std::endl; // prints 4 std::cout << spine(bst).height() << std::endl; // prints 6 std::cout << spine(bst) << std::endl; std::cout << "FIND 4 : " << bst.find(4) << std::endl; // prints 4 7 std::cout << "FIND 11 : " << bst.find(11) << std::endl; //prints nothing (possibly one space) std::cout << max_diff(bst) << std::endl; //prints 3 return 0; }