Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula to find distance between 2 3-D points

Status
Not open for further replies.

TheInsider

Programmer
Jul 17, 2000
796
CA
Hi,
Can someone give me a formula to find the distance between any two given 3-D points (x1, y1, z1) and (x2, y2, z2).
Thanks,

Rob Marriott
rob@career-connections.net
 
Thankyou all for looking at my thread but I think I found the solution already.

Rob Marriott
rob@career-connections.net
 
d==distance
d=sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2) )

if you make a class Point3D
friend double distance(P1,P2)
{
return sqrt( (P1.x-P2.x)*(P1.x-P2.x)+(P1.y-P2.y)*(P1.y-P2.y)+(P1.z-P2.z)*(P1.z-P2.z) )
}

 
Thanks cirebrainbech!

Rob Marriott
rob@career-connections.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top