Advertisement

Problems with Normal Generation & Circle co-ordinates

Started by June 19, 2001 05:31 AM
1 comment, last by Zeus_666 23 years, 7 months ago
Hi, I have written two small programs that were to generate my surface normals and the co-ordinates for drawing a circle. I however am having problems. The result''s of the programs some time include -1.#IND I have no idea what this means, the code is: Circles #include #include int radius =0, strips =0, i; float angle = 0.0, x =0.0, z = 0.0; void main () { cout << "Enter Radius, Number of strips:\n\n"; cin >> radius >> strips; for (i = 0; i <= strips; i++) { angle = ((float) i) / ((float) strips); angle = 360.0 * angle; x = radius * cos(angle); z = radius * sin(angle); cout << "x = " << x << "\nz = " << z << "\n\n"; } } Surface Normals #include #include float V1 [3], V2 [3], N [3], A [3], B [3], C [3]; float scale; char temp; bool quit; void main() { while (!quit) { cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; cout << "Please enter the co-ordinates for A, B, C:\n\n"; cout << "B****A\n* *\n* *\n* *\n* *\nC****D\n\n"; cin >> A[0] >> A[1] >> A[2]; cin >> B[0] >> B[1] >> B[2]; cin >> C[0] >> C[1] >> C[2]; cout << A[0] << A[1] << A[2]; cout << B[0] << B[1] << B[2]; cout << C[0] << C[1] << C[2]; V1[0] = B[0] - A[0]; V1[1] = B[1] - A[1]; V1[2] = B[2] - A[2]; V2[0] = C[0] - B[0]; V2[1] = C[1] - B[1]; V2[2] = C[2] - B[2]; N[0] = (V1[1] * V2[2]) - (V1[2] * V2[1]); N[1] = (V1[2] * V2[0]) - (V1[0] * V2[2]); N[2] = (V1[0] * V2[1]) - (V1[1] * V2[0]); scale = (float) sqrt ((N[0] * N[0]) + (N[1] * N[1]) + (N[1] * N[1])); N[0] = N[0] / scale; N[1] = N[1] / scale; N[2] = N[1] / scale; //B****A //* * //* * //* * //* * //C****D cout << "\n\n" << N[0] << N[1] << N[2] << "\n\n"; cout << "Any more surface normals calculate?\n\n"; cin >> temp; if (temp == ''n'') quit = true; } } I would be most grateful for help. Thanks, Paul
You are getting -1.#IND because of this line of your code:

  angle = ((float) i) / ((float) strips);  


Keep in mind that variable ''strips'' is initialized to 0, so, you are doing a divide by zero, therefore the compiler complains.
Advertisement
The circle program probably goes wrong because you''re feeding degrees to the cos/sin function instead of radians. Multiply your angle by 2*pi instead of 360.
The surface normal probably gives you false results because of the directional vectors you''re creating with the vector substraction. You should substract like this: V1 = C - A, V2 = C - B.

Good luck,

Jasper

This topic is closed to new replies.

Advertisement