用C++编写一个程序,计算直角坐标系中点a(x0,y0)到点b(x1,y1)的距离

如题所述

#include <map>
#include <cmath>
#include <iostream>

int main() {
    std::multimap<double,double> point;

    point.insert(std::pair<double,double>(0.0,0.0));
    point.insert(std::pair<double,double>(3.0,4.0));

    double dist_x = 0.0;
    double dist_y = 0.0;
    
    for ( std::multimap<double,double>::iterator it=point.begin(); it != point.end(); ++it ) {
        dist_x += it->first * it->first;
        dist_y += it->second * it->second;
    }
    std::cout << "Distance = " << sqrt(dist_x + dist_y) << std::endl;
}

温馨提示:内容为网友见解,仅供参考
无其他回答

求中点画线算法的c++代码...
直线方程:a*x+b*y+c=0, p1(x1,y1), p2(x2,y2)==> a=y1-y2;b=x2-x1.点到直线的距离:distance=|a*x0-b*y0+c|\/sqrt(a*a + b*b)设directionX,directionY分别为从(x1,y1)==>(x2,y2)的单位变化量(+\/-1)当直线偏向X轴时,当前象素为(xk, yk),下一个象素可能为...

C++定义一个点类一个距离类求两点之间的距离
float b):x(a),y(b){}private:\/\/点 有x y坐标float x;float y;friend class DISTANSE;\/\/声明距离类为友元;};\/\/距离类class DISTANSE{\/\/求距离要有两点;POINT_ p_1;POINT_ p_2;public:DISTANSE(float a,

c++编写一个点类Point,功能包括输出点的坐标,移动到新位置及输出它与...
int getY(); \/\/获取纵坐标 void setX(int iX); \/\/设置横坐标 void setY(int iY); \/\/设置纵坐标 float distance(Point p1, Point p2); \/\/计算两点的距离protected:private:int x; \/\/横坐标 int y; \/\/纵坐标};int main(){Point pos;Point pt(10, 10);Point pts(pt);cout << "获...

C++程序:定义线段类,计算两点间距离
x2,y1,y2; public: xd(double a, double b, double c, double d) { x1=a; y1=b; x2=c; y2=d; } double get_len() { return sqrt(pow(x1-x2,2)+pow(y1-y2,2)); }};int main(){ ...

c++算法: 以点O(x0,y0)为旋转中心,点A(x1,y1)旋转到点B(x2,y2),求...
double dx1 = x1 - x0;double dx2 = x2 - x0;double dy1 = y1 - y0;double dy2 = y2 - y0;double m1 = sqrt( dx1*dx1 + dy1*dy1 );double m2 = sqrt( dx2*dx2 + dy2*dy2 );\/\/ 除了180度和0度,你要自己区分下,其他应该都没问题。\/\/ 正表示逆时针, 负表示 顺时针...

c++编写一个点类Point,功能包括输出点的坐标,移动到新位置及输出它与...
class Point { private:double x;double y;public:Point();Point(double x1, double y1) {x=x1;y=y1} void set(double x1, double y1) {x=x1;y=y1} void Display() {cout << "(x,y)=(" << x << "," << y << ")" << endl;void move(double x1, double y1) {x=x1;...

求空间一个点到一条直线距离最近的点的坐标C++编程
int initline(line *l,point a,point b);int point2line(line l,point a,point *b);double p2p(point a,point b);\/*初始化三个点,其中前两个点用来做直线的*\/ initpoint(&points[0],1,2,3);initpoint(&points[1],-1,4,6);initpoint(&points[2],0,0,0);initline(&lne,points...

C++问题 计算两点之间的距离
using namespace std;int main(){ float x1,y1,x2,y2,s;cout <<"输入<x1,y1> <x2,y2>:\\n";cin>>x1>>y1>>x2>>y2;s=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));\/\/2次开根号函数,必须包含头文件cmath.cout <<"两点之间的距离为:"<<s<<endl;return 0;} ...

用c++程序输出图形,求高手写一个~
void DrawDot(int x,int y) \/\/画点 { temp[x][y]='*';} void DrawLine(int x1,int y1,int x2,int y2)\/\/画线 { int x,y,ix,iy,inc,plotx=x1,ploty=y1,i;int dx,dy;char flag;DrawDot(x1,y1);x=0;y=0;dx=x2-x1;ix=abs(dx);dy=y2-y1;iy=abs(dy);inc=ix>iy...

C++编程 求两个浮点数的点间距离
include <iostream.h> include <math.h> void main(){ float x1,y1,x2,y2;double distance;cout<<"请输入两点的X坐标和Y坐标"<<endl;cin>>x1>>y1>>x2>>y2;distance=sqrt(pow((x1-x2),2)+pow((y1-y2),2));cout<<"两点间的距离为 "<<distance<<endl;} ...

相似回答