# Thread: Calculating Surface Normals for Points

1. ## Calculating Surface Normals for Points

This is a problem that I have been stewing in for quite some time now, I need an equation I can understand to find surface normals. I'll try describing an example problem, with an analogy.

Imagine a hilly landscape. There is a flat "grid", or x-y chart, flat at sea level. "z" is the height of the land, where at sea level z=0. Below is a visualization, imagine looking down from a helicopter. x and y are labeled, numbers at each x,y is z, or height of the land.

Y
4|| 1| 3| 1| 0| 1|
3|| 1| 2| 4| 3| 2|
2|| 0| 5| 3| 7| 6|
1|| 0| 2| 1| 2| 0|
0|| 8| 0| 0| 0| 0|
|| 0| 1| 2| 3| 4|---X

So each (x,y,z) coordinate is a point, not a plane, but I need to calculate a normal for each point. This is only a small example, the real program has a much larger data set, and I eventually need to have an equation I can put down in programming code. I have looked online at many different websites, but my inexperience with vectors, and certain symbols I've never seen has left me bewildered. I'd appreciate any and all details, proofs or explanations.

2. Originally Posted by ericeps
This is a problem that I have been stewing in for quite some time now, I need an equation I can understand to find surface normals. I'll try describing an example problem, with an analogy.

Imagine a hilly landscape. There is a flat "grid", or x-y chart, flat at sea level. "z" is the height of the land, where at sea level z=0. Below is a visualization, imagine looking down from a helicopter. x and y are labeled, numbers at each x,y is z, or height of the land.

Y
4|| 1| 3| 1| 0| 1|
3|| 1| 2| 4| 3| 2|
2|| 0| 5| 3| 7| 6|
1|| 0| 2| 1| 2| 0|
0|| 8| 0| 0| 0| 0|
||-0|-1|-2|-3|-4|---X

So each (x,y,z) coordinate is a point, not a plane, but I need to calculate a normal for each point. This is only a small example, the real program has a much larger data set, and I eventually need to have an equation I can put down in programming code. I have looked online at many different websites, but my inexperience with vectors, and certain symbols I've never seen has left me bewildered. I'd appreciate any and all details, proofs or explanations.
I'm not an expert on this stuff, so don't take my opinion as 100%. But anyway, I'd know exactly how to solve your problem if this "grid" of x and y could be put into an equation. Like, say on this grid we want to figure the "hieght of the land", if we had an equation $f(x, y)$, which uses the variables x and y (the placement on the grid) to calculate the hieght 'z'. So, if we could figure out a way to write all the points as a function:

$z = f(x, y)$

Then I know how to solve this problem. Was an equation provided or are you supposed to figure it out yourself? Now, granted, I bet there is a way to calculate the surface normals without an exact equation, I just don't know how. Check out this link:

Normal Vector -- from Wolfram MathWorld

Basically, this says that the normal vector at any point $(x_0, y_0)$ is:

$N = \{ f_x(x_0, y_0) , f_y(x_0, y_0), -1 \}$

They $f_x \;\; \mathrm{and} \;\; f_y$ just denote the partial derivite of $f$. What that basically means is that if, lets just say for example, we had a grid with the following equation:

$f( x, y) = z =x^2 + y^2$

Then to find $f_x$ you just take the derivite with respect to x, and let y act as a constant. To find $f_y$ you let x act as a constant, so:

$f_x(x, y) = 2x$

and

$f_y(x, y) = 2y$

Does that make sense?

3. Thanks for the reply, here's an update, mainly I need some clarification to one of the equations you posted(the second one below):

$z = f(x, y)$
I believe this is a correct equation to describe the "landscape".

$N = \{ f_x(x_0, y_0) , f_y(x_0, y_0), -1 \}$
I do not understand this equation, can you please explain it more? What is the difference between $f_x(x_0, y_0)$ and $f_y(x_0,y_0)$ ?
Also, I am only vaguely familiar with derivatives, so please explain it.

Was an equation provided or are you supposed to figure it out yourself?
No equation provided, this is part of a programming project I have been working on. The surface normals will be used to add correct shading to a 3D landscape.

4. Since you are given the surface as an array of points, the simplest thing to do is to use nearby points to find two vectors at the given point, then take the cross product.

At, for example, x= 2, y= 2, z= 3 so the point is (2, 2, 3). We can take (3, 2, 7) and (2, 3, 4) as nearby points so we have vectors <3-2, 2- 2, 7- 3>= < 1, 0, 4> and <2- 2, 3- 2, 4- 3>= <0, 1, 1>.

Their cross product is $(0*1- 4*1)\vec{i}- (1*1- 0*4)\vec{j}+ (1*1- 0*0)\vec{k}= -4\vec{i}- \vec{j}+ \vec{k}$ is normal to the surface at that point.

Of course, there are several other points you could take as "nearby" resulting in different vectors and a different normal. There is no single "correct" answer here because you are not given the surface accurately enough.

But, quite frankly, you may not have enough mathematics to really understand all this. Since you do not know the difference between $f_x(x_0, y_0)$ and $f_z(x_0, y_0)$ (the first is the rate of change of f as x changes and y does not at the point $(x_0, y_0)$ and the second is the rate of change as y changes and x does not.) you may not be familiar with the "cross product" of two vectors.

What mfetch22 is suggesting you do is take the information you have to find the equation of a surface containing those points, then look at "infinitesmal" vectors in the x and y direction and take the cross product of those vectors whereas I am suggesting you just use the numbers you are given to create those vectors.

5. Ok, I think I'm starting to get a better grasp, and can calculate the normal for a plane using 3 points. Could calculating the normals for each facet that uses the point in question, and then average them all out, give a good approximation for what it would be? Make sense? To do this I'm thinking to take vector normals V, U, W. and do (V.x+U.x+W.x)/3 to find the average x, and the same for y and z.

But, quite frankly, you may not have enough mathematics to really understand all this
Maybe so, that's why I'm here, but most if not all is just review from a mathematic hiatus.