Please check my maths! (as I'm the big thicko when it comes to maths!)
I wonder if someone could possibly check my maths here as I''m not sure this is right...
What I have done is have a (3D) object read in from an external file and drawn to screen but I also want to draw the points that make up that object as they would be mapped onto a unit sphere...
Therefore I have a center point (x0,y0,z0) and then the 8 points that make up the objevt to be mapped (x,y,z). I am unsure of the maths behind for obtaining the coordinates for the mapped points (x1, y1, z1), the following is what I have done:
x1 = x0 + ((x - x0)/d)
y1 = y0 + ((y - y0)/d)
z1 = z0 + ((z - z0)/d)
where d = square root of (x-x0)squared + (y-y0)squared + (z-z0)squared
However I''m not sure if the end result is correctly mapped to a unit sphere, could someone please tell me if I''ve done this correctly as I''m terrible at maths (why oh why did I start graphics programming!) and if this is wrong could anyone point me in the right direction?
Thanks,
Ben....
Given any point in 3d space a ray drawn from the origin through that point will intersect a unit sphere at the normalized vector of that point.
Anotherwords normalize the vector created by you point... (my code for normalizing a vector)
void VECTOR::Normalize(){
double m;
//calculate the length of the vector
m = (X*X) + (Y*Y) + (Z*Z);
m = (double)sqrt(m);
// if the length is zero then the vector is zero so return
if(m == 0)
return;
//Scale the vector to a unit length
X /= m;
Y /= m;
Z /= m;
}
This will be the point on a unit shpere at the origin that the point is on.
If the sphere is not at the origin then you must subtract the origin of the sphere from you point first then translate it back to the sphere space by adding the spheres origin back to it...
p -= o;
p.Normalize();
p += 0;
Let me know if this helps.
l8r,
Rob
http://tannara.2y.net/
Anotherwords normalize the vector created by you point... (my code for normalizing a vector)
void VECTOR::Normalize(){
double m;
//calculate the length of the vector
m = (X*X) + (Y*Y) + (Z*Z);
m = (double)sqrt(m);
// if the length is zero then the vector is zero so return
if(m == 0)
return;
//Scale the vector to a unit length
X /= m;
Y /= m;
Z /= m;
}
This will be the point on a unit shpere at the origin that the point is on.
If the sphere is not at the origin then you must subtract the origin of the sphere from you point first then translate it back to the sphere space by adding the spheres origin back to it...
p -= o;
p.Normalize();
p += 0;
Let me know if this helps.
l8r,
Rob
http://tannara.2y.net/
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement