Working with ellipsoids and plane projection..

Started by
14 comments, last by osso 16 years, 1 month ago
Say your ellipsoid has equation

F(x,y,z) = A*x^2 + B*y^2 + C*z^2 - 1 = 0

(not a general ellipsoid, but it looks like this is the case you are dealing with)

You can find a normal vector by computing the gradient of F(x,y,z):

(2*A*x, 2*B*y, 2*C*z)

Now divide by its length if you need it to have length 1. Of course, you can save yourself the multiplications by 2.
Advertisement
my equation for calculating the normal vector is based on the following

(2x/a^2, 2y/b^2, 2z/c^2) = n

Does that mean n is actually giving me the gradient directional vector from the surface point?

therefore with a few calculations, I can use the cross product of the gradient vector and the surface vector to calculate the perpendicular normal vector from the point which lays on the surface?
Your existing method for calculating the normal
Quote:normal[0] = ((point[0])/pow((double)radius[0],2));
normal[1] = ((point[1])/pow((double)radius[1],2));
normal[2] = ((point[2])/pow((double)radius[2],2));
looks "OK"...
It will give you the correct direction... however...
As you've found the result varies in length... which then affects the dot products with other things.

To correct this, normalize the normal vector before you use it.
Calculate it's length, sqrt(normal[0]^2 + normal[1]^2 + normal[2]^2)
and divide each of the elements normal by that length.

The result will be a unit vector (length 1) but still pointing in the same (the right) direction.

[Edited by - daftasbrush on April 2, 2008 4:38:38 AM]
Thanks daftasbrush, I thought it would've given me a the normal direction, I got confused when alvaro mentioned computing the gradient!

I am going to knock up an opengl testharness so i can determine once and for all where the direction is going lol..

Quote:Original post by osso
Thanks daftasbrush, I thought it would've given me a the normal direction, I got confused when alvaro mentioned computing the gradient!

Sorry about that. I think you are having understandable confusion between the terms "normal" and "normalized". A normal vector is one that is perpendicular, but it can be of any size. A normalized vector is one that has the desired direction specified by another vector, but whose size is 1.

The thing about computing the gradient is a general way of computing normals for things defined by implicit equations. I didn't mean to add to the confusion.
Thats fine alvaro, eitherway, thanks for contributing to the thread! I am pretty new to this game, experienced software engineer but never had the opportunity to play around with 3d modelling until now, and my maths is a little rusty.

This topic is closed to new replies.

Advertisement