Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫  π  -¹ ² ³ °

You are not logged in.

## #1 2006-06-22 05:53:44

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

### calculating normal vector from equation for a shape

ive heard that from the equation for a shape, lets say the equation for a torus, that from the coordiante for a point on the torus, you can arbitarily find the normal vector via differentiating or something, ofcourse theres other ways of getting normal with a torus, like with a sphere etc

but for strange shapes that have no such easy way, there must be some way of calculating a normal vector just from the equaiton, in the same way that from a curve, you can find the tangent vector by finding the gradient

The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

## #2 2006-06-23 04:43:50

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

### Re: calculating normal vector from equation for a shape

Yes, but how do you differentiate in 3-D?

igloo myrtilles fourmis

Offline

## #3 2006-06-23 04:46:59

luca
Guest

### Re: calculating normal vector from equation for a shape

John E. Franklin wrote:

Yes, but how do you differentiate in 3-D?

## #4 2006-06-23 05:38:42

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

### Re: calculating normal vector from equation for a shape

Just thinking...
Is it possible to get 2-D equations of cross-sections at various angles that go thru the point of interest??  I don't know.

igloo myrtilles fourmis

Offline

## #5 2006-06-23 15:10:57

Zhylliolom
Real Member
Registered: 2005-09-05
Posts: 412

### Re: calculating normal vector from equation for a shape

Sorry for taking a little while to respond to this, but I take forever to type up LaTeX and I had to head out for the day yesterday while I was typing it up. Anyway, here's my simple calculus/vector analysis method for doing it.

For a torus:

Since you mentioned a torus first, I'll use it for the first example. The parametric expression for a torus is

where c is the distance from the center to the inner boundary of the torus and a is the radius of the torus "tube."

Now, first we want to find the tangent vectors to the "curves" of the torus. To do this, we calculate the partial derivatives:

Since the magnitude of the vectors is irrevelant (unless the magnitude is 0, then that's no fun), we can simplify the partial derivatives by dividing through by a in f[sub]u[/sub] and (c + a cos u) in f[sub]v[/sub]:

Now we may simply put our parameter values u and v in for our point of interest. We have two partial derivatives here, so for our arbitrary parameter values, we will get two tangent vectors. This is a good thing, since from basic vector analysis, we know how to find a vector mutually perpendicular to two given vectors in R[sup]3[/sup]: the cross product. So now what we merely need to do is take the cross product of the two tangent vectors obtained:

This process can be used for other surfaces, such as a sphere (parametrically defined in R[sup]3[/sup] by [r cos u sin v, r sin u sin v, r cos v]).

I leave you with the following note:

Edits: It seems that the forum is thinner than the preview space... and I can't get some of the spacing right still. Oh well.

Last edited by Zhylliolom (2006-06-23 15:17:47)

Offline

## #6 2006-06-23 15:11:30

George,Y
Member
Registered: 2006-03-12
Posts: 1,306

### Re: calculating normal vector from equation for a shape

You'd better get a vector calculus book or a calculus book with sufficient vector calculus.

X'(y-Xβ)=0

Offline

## #7 2006-06-23 18:45:47

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

### Re: calculating normal vector from equation for a shape

wow Zhylliolom, very interesting, but is it possible supposing there is no parametric definition? In a way such that it is a single equation equating zero for a point f(x,y,z)

for example, a torus again, but rather than parametric equations

that it were a single equation equating zero

ive never done partial derivatives before, but i guess you could do a partial derivative for x,y,z ... only what use would that be?

but for the sake of it, is that correct?

Last edited by luca-deltodesco (2006-06-23 18:53:11)

The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

## #8 2006-06-23 19:24:44

Zhylliolom
Real Member
Registered: 2005-09-05
Posts: 412

### Re: calculating normal vector from equation for a shape

A lot of the work is cleared away if the surface requires no parametric definition. In fact, if F(x, y, z)  = 0 is the equation of the surface, then the normal to the surface is

where (a, b, c) is the arbitrary point of the surface which we wish to find the normal and the operator

is defined by

is called the gradient of F.

So, for the surface you defined and found the first order partial derivatives for in your previous post,

Offline

## #9 2006-06-23 20:05:42

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

### Re: calculating normal vector from equation for a shape

what really annoys me

is that before i even posted this thread, i had tried just that

i took the surface equation for a torus equating zero, then differentaited with respect to x,y,z (i didnt know it was called partial differentiation, i just did it) and then used it for the normals x,y,z normalizing, and yet it didnt seem to work, so i asked here

and now ive tried it again, and it works perfectly! :X

thankyou very much for your help. but one last thing

what does the |(a,b,c) notation actually mean? Ive never seen it before

Last edited by luca-deltodesco (2006-06-23 20:06:09)

The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

## #10 2006-06-23 20:24:55

Zhylliolom
Real Member
Registered: 2005-09-05
Posts: 412

### Re: calculating normal vector from equation for a shape

luca-deltodesco wrote:

what does the |(a,b,c) notation actually mean? Ive never seen it before

It tells the reader to evaluate the preceding expression given that (x, y, z) = (a, b, c), where a, b, c are arbitrary points. For example:

Basically, in this situation, the notation tells you to evaluate the expression at the point indicated in the subscript.

I see the notation a lot with derivatives. Suppose y = x². Then

Offline

## #11 2006-06-23 20:25:19

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

### Re: calculating normal vector from equation for a shape

ah i get it now

note that ive ommited the '4x' in it, since it doesnt make any difference to the resulting normalized vector

and infact, this algebraic approach, is actually faster than the geometrical approach

The geometrical approach requires normalizing a vector, then subtracting, then normalizing again, and only works when R>r, this is only requires one normalisation after finding the vector, and gamma and alpha have already been calculated when finding the intersection with a ray

now all i need, is to calculate the tangent space at a given point on a surface

Last edited by luca-deltodesco (2006-06-23 20:30:22)

The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

## #12 2006-06-23 20:53:16

Zhylliolom
Real Member
Registered: 2005-09-05
Posts: 412

### Re: calculating normal vector from equation for a shape

If by "tangent space" you mean the tangent plane to the surface at a given point, that is just as easy to determine.

The rectangular form of the plane is given by

Edit: Hey, it looks better!

Last edited by Zhylliolom (2006-06-23 20:54:35)

Offline

## #13 2006-06-23 20:56:35

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

### Re: calculating normal vector from equation for a shape

ah wait, i think i have an easy solid method of calculating the tangent space, which will work quite well for what i need too
i need one of the tangents to be in the x,z plane

so i should be able to do this

taking the normal n.
normalize the vector after projecting it onto the x,z plane i.e. normalize (n.x,0,n.z), lets say its (a,0,b), then the first tangent vector will be (-b,0,a)
and then the second tangent vector via cross product

in the case that the normal vector is (0,1,0) you can use base axis (1,0,0) and (0,0,1)

The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

## #14 2006-06-23 21:27:19

luca
Guest

### Re: calculating normal vector from equation for a shape

oh and by tangent space, i meant calculating 3 vectors from a surface, the normal, and two perpendicular tangents. i.e. to calculate a rotational matrix to transform a point from world space to the same base as the surface normal

its needed for stuff like normal mapping in graphical programming