Given a three-dimensional plane and therefore three coordinates, the task is to find the distance between the given points and display the result.
On the three-dimensional plane, there are three coordinate axes. The coordinates of the x-axis are (x1, y1, z1), the coordinates of the y-axis are (x2, y2, z2), and the coordinates of the z-axis are (x3, y3,z). There is a direct formula for calculating the distance between them as follows
$$\sqrt{\lgroup x2-x1\rgroup^{2} \lgroup y2-y1\rgroup^{2} \lgroup z2 -z1\rgroup^{2}}$$
The following is a diagram showing three different axes and their coordinates
The method used below is as follows −
- Input coordinates (x1, y1, z1), (x2, y2, z2) and (x3, y3, z3)
- Apply the formula to calculate the difference between these points
- Print distance
Algorithm
Start Step 1-> declare function to calculate distance between three point void three_dis(float x1, float y1, float z1, float x2, float y2, float z2) set float dis = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) + pow(z2 - z1, 2) * 1.0) print dis step 2-> In main() Set float x1 = 4 Set float y1 = 9 Set float z1 = -3 Set float x2 = 5 Set float y2 = 10 Set float z2 = 9 Call three_dis(x1, y1, z1, x2, y2, z2) Stop
Example
's translation is:Example
#include <stdio.h> #include<math.h> //function to find distance bewteen 3 point 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) * 1.0); printf("Distance between 3 points are : %f", dis); return; } int main() { float x1 = 4; float y1 = 9; float z1 = -3; float x2 = 5; float y2 = 10; float z2 = 9; three_dis(x1, y1, z1, x2, y2, z2); return 0; }
Output
If we run the above code it will generate the following output
Distance between 3 points are : 12.083046
The above is the detailed content of C program to calculate distance between three points in 3D space. For more information, please follow other related articles on the PHP Chinese website!

给定一个三维平面,因此有三个坐标,任务是找到给定点之间的距离并显示结果。在三维平面上,有三个坐标轴,x轴的坐标为(x1,y1,z1),y轴的坐标为(x2,y2,z2),z轴的坐标为(x3,y3,z)。计算它们之间的距离有一个直接的公式如下所示$$\sqrt{\lgroupx2-x1\rgroup^{2}+\lgroupy2-y1\rgroup^{2}+\lgroupz2-z1\rgroup^{2}}$$下面是表示三个不同坐标轴及其坐标的图示下面使用的方法如下−输入坐标(x1,

本文转载自微信公众号「活在信息时代」,作者活在信息时代。转载本文请联系活在信息时代公众号。在机器学习中,一个基础的概念就是如何判断两个样本之间的差异,从而能够评价两个样本之间的相似性和类别等信息。而判断这种相似性的度量就是两个样本在特征空间内的距离。根据数据特征的不同,度量方法有很多种。一般而言,对两个数据样本x,y,定义一个函数d(x,y),如果定义其为两个样本之间的距离,那么d(x,y)则需要满足以下几条基本性质:非负性:d(x,y)>=0同一性:d(x,y)=0 ⇔ x=y对

在其年度开发者大会上,苹果推出了下一代操作系统来为其设备套件提供支持。像往常一样,iOS17是所有主要变化的核心,具有实时语音邮件、消息转录、实时贴纸、待机模式、全屏实时活动、交互式小部件等功能。在这些新增功能中脱颖而出的功能之一是“屏幕距离”。这是一项以健康为中心的功能,专注于防止iPhone屏幕上的眼睛疲劳和近视。在这篇文章中,我们将解释什么是屏幕距离以及如何在iOS17中启用它。什么是iOS17上的屏幕距离?作为iOS17推出的新健康功能的一部分,Apple提供了屏幕距离功能,以帮助用户预

iOS17更新中的屏幕距离功能是什么?苹果在iPhone上提供了屏幕距离功能,以帮助用户防止眼睛疲劳和近视风险。该功能(在iOS17或更高版本上可用)将利用iPhone的原深感摄像头(也有助于FaceID的摄像头)来测量脸部与手机之间的距离。如果“屏幕距离”检测到您将iPhone握在12英寸或30厘米以下的时间很长,它会提示您与iPhone屏幕保持距离。当您的设备检测到它距离脸部不到12英寸时,您会在屏幕上看到“iPhone太近”消息,并建议您应该保持距离以保护您的视力。只有当您将设备放在更远的

Givenwithapositiveintegervaluelet’ssay‘val’andthetaskistoprintthevalueofbinomialcoefficientB(n,k)where,nandkbeanyvaluebetween0tovalandhencedisplaytheresult.WhatisBinomialCoefficientBinomialcoefficient(n,k)istheorderofcho

在这里,我们将解决C语言中的最小成本路径问题。这意味着在2D矩阵上完成,其中每个单元格都有一个移动成本。我们必须找到一条从左上角到右下角且行程成本最小的路径。您只能从给定单元格向下和右下遍历单元格。为了解决这个特定问题,动态编程比递归更好。给定成本矩阵cost[][]和位置(m,n),我们必须编写一个函数,返回从(0,0)到达(m,n)的最小路径成本到达(m,n)的路径的总成本是该路径上所有成本的总和(包括源和目的地)。假设−所有成本是积极的。输入矩阵中不存在负成本循环示例查找到(2,2)的最小

程序说明五维体数是帕斯卡三角形的任意一行中第五个数字,从左到右或从右到左开始,起始于5项行14641。这种数字的前几个是1,5,15,35,70,126,210,330,495,715,1001,1365Pentatopenumbersbelongintheclassoffiguratenumbers,whichcanberepresentedasregular,discretegeometricpatterns.Theformulaforthenthpentatopicnumberis$$\l

我们在三角学中最常使用的比率包括正弦、余弦、正切等等。您可以使用角度来计算这些比率。如果我们知道比率值,我们还可以使用反三角函数计算角度。本课程将向您展示如何使用C++的反正切(arctan)函数,使用正切值(以弧度为单位)计算角度。atan()函数使用atan()技术和反三角正切函数计算角度。C++标准库包含这个函数。在使用这种方法之前,我们必须导入cmath库。此方法返回以弧度为单位的角度,并采用正切值作为参数。以下使用简单的语法-语法#include<cmath>atan(&l


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
