Finding points on a sphere close to a given point
Hi all,
I''m having a problem with normal generation; I''m using a Perlin noise function to deform points on a sphere and want to calculate a normal for a given point post-deformation.
So, what I''d like to do is to get the coords of three points very close to my current point; p1, p2 and p3. These points must also lie on the sphere. That way, I can apply my noise function to p1, p2 and p3 to generate their deformed coordinates and use these new coords to find a normal to the plane they all lie on:
normal = (deformed_p1 - deformed_p2) x (deformed_p3 - deformed_p2)
That normal should then be very close to the true normal for my original point.
Since I figured all that out, I''m a little embarassed that my problem lies in finding p1, p2 and p3 so that they''re close to my original point and still on the sphere...
Any help anyone can offer is much appreciated.
Many thanks,
IainC
www.coldcity.com
code, pics, life
[size="2"]www.coldcity.com code, art, life
To illustrate further, here's a non-working version where I've just made two points close to the point under test that aren't necessarily on the sphere...
GLfloat point[3] is the point under test.
www.coldcity.com
code, pics, life
[edited by - IainC on October 11, 2002 10:40:17 AM]
GLfloat point[3] is the point under test.
// It's the three lines below that need changed so I have something that lies upon the sphere... GLfloat p1[3] = {point[0], point[1], point[2]}; GLfloat p2[3] = {point[0] + 0.01f, point[1] + 0.01f, point[2] + 0.01f}; GLfloat p3[3] = {point[0] - 0.01f, point[1] - 0.01f, point[2] - 0.01f};// Now deform the points by the noise function GLfloat p1Deform = GetHeight(p1); GLfloat p2Deform = GetHeight(p2); GLfloat p3Deform = GetHeight(p3); p1[0] += p1[0] * p1Deform; p1[0] += p1[1] * p1Deform; p1[0] += p1[2] * p1Deform; p2[0] += p2[0] * p2Deform; p2[0] += p2[1] * p2Deform; p2[0] += p2[2] * p2Deform; p3[0] += p3[0] * p3Deform; p3[0] += p3[1] * p3Deform; p3[0] += p3[2] * p3Deform;// Find two vectors that lie within the plane (ie find vectors for two of the edges) GLfloat p1_to_p2[3] = {p1[0] - p3[0], p1[1] - p3[1], p1[2] - p3[2]}; GLfloat p2_to_p3[3] = {p2[0] - p3[0], p2[1] - p3[1], p2[2] - p3[2]}; // And the normalised cross product of these two vectors will give us the normal we seek GLfloat normal[3]; NormalizedCrossProduct (p1, p2, normal);// Spit out the normal into OpenGL or whatever glNormal3f (normal[0], normal[1], normal[2]);
www.coldcity.com
code, pics, life
[edited by - IainC on October 11, 2002 10:40:17 AM]
[size="2"]www.coldcity.com code, art, life
I don''t follow you during your whole problem, but finding a point on a sphere closest to another point is pretty straightforward: it lies on the axis between the center of the sphere and the point, and it''s r units away from the center of the sphere.
You probably already knew that; to find other points close to that one, use spherical coordinates, and manipulate only the phi and theta components.
Could you state your question more precisely?
Cédric
You probably already knew that; to find other points close to that one, use spherical coordinates, and manipulate only the phi and theta components.
Could you state your question more precisely?
Cédric
cedricl, sorry I didn''t state my problem as clearly as I could have, but you''ve solved it for me anyway 
I''ll just translate my current Cartesian coords into Siegelian, vary phi and z slightly, and convert back.
Many thanks!
I.
www.coldcity.com
code, pics, life

I''ll just translate my current Cartesian coords into Siegelian, vary phi and z slightly, and convert back.
Many thanks!
I.
www.coldcity.com
code, pics, life
[size="2"]www.coldcity.com code, art, life
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement