Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

JmarsKoder

3d Question

This topic is 6201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do you find the average plane from a set of points. I know there was a paper on it but I cant find it anywhere on the next if you know where it is let me know, it was called “Finding the Average Plane for a Set of Points” by Niki (http://www.thecore.de/avgplane.pdf). the problme is the link is broken. thanks Reality Makes Me XIC I hack code: passion is my feul. Use my programs, experience genius. http://www.x-i-c.com/

Share this post


Link to post
Share on other sites
Advertisement
  
// Create a plane from 3 points

GPlane* Game3D::createPlane( GVector* a, GVector* b, GVector* c )
{
GPlane* plane = new GPlane();

GVector q;
GVector v;

q.x = b->x - a->x; v.x = b->x - c->x;
q.y = b->y - a->y; v.x = b->y - c->y;
q.z = b->y - a->y; v.x = b->z - c->z;
plane->normal = crossProduct( &q, &v );
normalizeVector( &plane->normal );

// calculate distance to origin

plane->distance = dotProduct (&plane->normal, a); // you could also use b or c

return plane;
}

GVector Game3D::crossProduct( GVector* v1, GVector* v2 )
{
GVector result;

result.x = ( v1->y * v2->z ) - ( v1->z * v2->y );
result.y = ( v1->z * v2->x ) - ( v1->x * v2->z );
result.z = ( v1->x * v2->y ) - ( v1->y * v2->x );
return result;
}


float Game3D::dotProduct( GVector* v1, GVector* v2 )
{
float dot;
dot = (v1->x * v2->x + v1->y * v2->y + v1->z * v2->z);
return dot;
}

void Game3D::normalizeVector( GVector* vector )
{
float length = (float)sqrt( (vector->x*vector->x) + (vector->y*vector->y) + (vector->z*vector->z) );

vector->x /= length;
vector->y /= length;
vector->z /= length;
}



Any questions just ask

Seeya
Krippy

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!