Distance between Point A and Point B?
I need to program a function that will give me a distance value between the viewpoint, and either a polygon or a point.
I need this for a LOD system I am working on, the further the distance, the lower the number of polygons I will draw.
However I freely admit I am poor at math (bad English education system), and need a simple function to do it.
I have read lots of complex math papers on the www - but all are too complicated for me.
Please help, Alex.
xPOINT pointA,pointB,AtoB;
pointA.x = 0;
pointA.y = 5;
pointA.z = 3;
pointB.x = 0;
pointB.y = 2;
pointB.z = 0;
// Generate direction vector from pointA to pointB
AtoB.x = pointA.x - pointB.x;
AtoB.y = pointA.y - pointB.y;
AtoB.z = pointA.z - pointB.z;
// Find length of this direction vector
distance = sqrt((AtoB.x * AtoB.x)+(AtoB.y * AtoB.y)+(AtoB.z * AtoB.z));
pointA.x = 0;
pointA.y = 5;
pointA.z = 3;
pointB.x = 0;
pointB.y = 2;
pointB.z = 0;
// Generate direction vector from pointA to pointB
AtoB.x = pointA.x - pointB.x;
AtoB.y = pointA.y - pointB.y;
AtoB.z = pointA.z - pointB.z;
// Find length of this direction vector
distance = sqrt((AtoB.x * AtoB.x)+(AtoB.y * AtoB.y)+(AtoB.z * AtoB.z));
squarerr ((v2[0]-v1[0])*(v2[0]-v1[0])+(v2[1]-v1[1])*(v2[1]-v1[1])+(v2[2]-v1[2])*(v2[2]-v1[2])))
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement