简体   繁体   English

如何在数组中找到坐标为 (x1, y1) 和 (x2, y2) 的两点之间的直线长度?

[英]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 * xpow(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.

相关问题 如何使用 c 编程语言从每行格式为 (x1,y1) (x2, y2) 的文件中提取一些 x 和 y 坐标? - How can some x and y coordinates be pulled out of a file where each line is in the form of (x1,y1) (x2, y2) with the c progamming language? 声明并定义函数distance(),以找到c中两点(x [0],y [0])和(x [1],y [1])之间的欧几里得距离 - Declare and define the function distance() to find the Euclidean distance between the two points (x[0], y[0]) and (x[1], y[1]) in c 如何将(纬度,经度)转换为(x,y)坐标? - How do I convert (latitude,longitude) into (x,y) coordinates? OpenGL-glVertex2f(x,y)中的x和y之间的映射到屏幕整数坐标 - OpenGL - Mapping between x and y in glVertex2f(x, y) to screen integer coordinates 如何计算给定坐标(x,y)我可以走的路径数,使用一步/两步向下或向左到达(0.0)? 在 C - how to count the number of paths I can take given a coordinates (x,y) using one step/two steps down or left to get to (0.0)? in C 用c编程中的函数计算2个坐标之间的距离(x,y,z) - Calculate distance between 2 coordinates with function in c programing (x,y,z) 如果用户输入“sum(x,y)”我怎样才能得到 x 和 y 作为双打 - If user inputs “sum(x,y)” how can I get x and y as doubles 在C中使用x / y坐标索引2D数组的惯例是什么? - What is the convention of indexing 2D array with x/y coordinates in C? 在一维数组中索引不规则网格X,Y,Z坐标 - Indexing irregular grid X,Y,Z coordinates in a 1D array 为什么程序输出x1 = Nan,x2 = Nan? - Why does program output x1 = Nan, x2 = Nan?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM