[英]How can i find the length of a line between two points with coordinates (x1, y1) and (x2, y2) in array?
How can i find the length of a line between two points with coordinates (x1, y1) and (x2, y2) in array?如何在数组中找到坐标为 (x1, y1) 和 (x2, y2) 的两点之间的直线长度? For example i have 2 arrays: arrayX[10] and arrayY[10].例如,我有 2 个 arrays:arrayX[10] 和 arrayY[10]。
I have to find the results of the following operations in the loop and save them in the result array:我必须在循环中找到以下操作的结果并将它们保存在结果数组中:
sqrt((arrayX[0]- arrayX[1])^2+(arrayY[0]-arrayY[1]^2))
sqrt((arrayX[1]- arrayX[2])^2+(arrayY[1]-arrayY[2]^2))
. .
. .
. .
In C there is no exponentiation operator.在 C 中没有指数运算符。 To compute x^2
either use x * x
or pow(x, 2)
from math.h
.要计算x^2
,请使用math.h
中的x * x
或pow(x, 2)
。
Possible solution可能的解决方案
double dist[9];
for (int i = 0; i + 1 < 10; ++i) {
double dx = arrayX[i]- arrayX[i + 1];
double dy = arrayY[i]- arrayY[i + 1];
dist[i] = sqrt(dx *dx + dy * dy);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.