# Problems with Normal Generation & Circle co-ordinates

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 <iostream.h>
#include <math.h>

int radius =0, strips =0, i;
float angle = 0.0, x =0.0, z = 0.0;

void main ()
{
cout << "Enter Radius, Number of strips:

";
cin >> radius >> strips;

``````for (i = 0; i &lt;= strips; i++)
{
angle = ((float) i) / ((float) strips);
angle = 360.0 * angle;
x = radius * cos(angle);
z = radius * sin(angle);

cout &lt;&lt; "x = " &lt;&lt; x &lt;&lt; "
``````

z = " << z << "

";

``````}
``````

}

Surface Normals

#include <math.h>
#include <iostream.h>

float V1 , V2 , N , A , B , C ;
float scale;
char temp;
bool quit;

void main()
{
while (!quit) {
cout << "

";
cout << "Please enter the co-ordinates for A, B, C:

";
cout << "B****A

C****D

";

``````	cin &gt;&gt; A &gt;&gt; A &gt;&gt; A;
cin &gt;&gt; B &gt;&gt; B &gt;&gt; B;
cin &gt;&gt; C &gt;&gt; C &gt;&gt; C;

cout &lt;&lt; A &lt;&lt; A &lt;&lt; A;
cout &lt;&lt; B &lt;&lt; B &lt;&lt; B;
cout &lt;&lt; C &lt;&lt; C &lt;&lt; C;

V1 = B - A;
V1 = B - A;
V1 = B - A;
V2 = C - B;
V2 = C - B;
V2 = C - B;

N = (V1 * V2) - (V1 * V2);
N = (V1 * V2) - (V1 * V2);
N = (V1 * V2) - (V1 * V2);

scale = (float) sqrt ((N * N) + (N * N) + (N * N));

N = N / scale;
N = N / scale;
N = N / scale;

//B****A
//*    *
//*    *
//*    *
//*    *
//C****D

cout &lt;&lt; "
``````

" << N << N << N << "

";
cout << "Any more surface normals calculate?

";
cin >> temp;

``````	if (temp == 'n')
quit = true;
}
``````

}

I would be most grateful for help.

Thanks, Paul

Not sure where you get -1.#IND. Sounds like some floating point error.

You sure following code is ok?:

scale = (float) sqrt ((N * N) + (N * N) + (N * N));
N = N / scale;
N = N / scale;
N = N / scale;

Normalizing a 3d vector?

Try:

scale = (float) sqrt ((N * N) + (N * N) + (N * N));
N = N / scale;
N = N / scale;
N = N / scale;

And maybe check for zero result on scale.

Hi,
The surface normal error occurs when i give the following data:

25.0 6.0 -35.0 -25.0 6.0 -35.0 -25.0 -1.0 -35.0

Did you see the index error AndersO pointed to?

Yes, reread my previous message! Using those vectors you specified will eventually end in a divide by zero!. (In the normalizing code).

Cheers!

Well, I’m a C/C++ programmer with a part-time job with the government. My experience thru mass debugging and programming shows that -1.#IND is a imaginary number (like the sq. rt. of -5 or so, like i). Usually if it’s a Div. by 0 it displays 0 and later shows encryptic bugs. However, it sounds more like an imaginary number. Step thru your program and find out what number is causing all of this.

Hope that helps out

Ok, made that number change pointed out and now i have the results from the above data:

-1.#IND -1.#IND -1.#INF

I’m stuck, when i do the calculation on my calculator i get 0 for the first value

Hi,
Fixed the index error pointed out, me tired, surface normal program now working, i think i will take a break fro mthis as i have been working on my program all yesterday and all today. Thanks, i will look at the circle generation tomorrow.

Paul