คำนวณระยะทางในพื้นที่ 3 มิติระหว่างจุด (x1,y1,z1) และ (x2,y2,z2) ด้วยสูตร √[(x2-x1)² + (y2-y1)² + (z2-z1)²]
ตัวอย่าง
(4,9,-3) และ (5,10,9) → Distance = 12.083046
โค้ดตัวอย่าง
#include <stdio.h>
#include <math.h>
void three_dis(float x1, float y1, float z1, float x2, float y2, float z2) {
float dis = sqrt(pow(x2-x1,2) + pow(y2-y1,2) + pow(z2-z1,2));
printf("Distance between 3 points are: %f", dis);
}
int main() {
float x1=4, y1=9, z1=-3, x2=5, y2=10, z2=9;
three_dis(x1, y1, z1, x2, y2, z2);
return 0;
}
ผลลัพธ์
Distance between 3 points are: 12.083046