数学思想:利用圆方程和直线方程
已知两点坐标和半径求圆心坐标程序
#include <iostream>
#include <fstream>
#include <cmath> using namespace std; ofstream fout; typedef struct
{
double x;
double y;
}Point; double Y_Coordinates(double x,double y,double k,double x0);//4个参数
void Circle_Center(Point p1,Point p2,double dRadius);
bool Data_Validation(Point p1,Point p2,double dRadius);
void ReadData(Point &p1,Point &p2,double &dRadius); void main()
{
Point p1,p2;
double dRadius = 0.0; ReadData(p1,p2,dRadius); fout.open("Result.txt");
Circle_Center(p1,p2,dRadius);
fout.close();
} void Circle_Center(Point p1,Point p2,double dRadius)
{
double k = 0.0,k_verticle = 0.0;
double mid_x = 0.0,mid_y = 0.0;
double a = 1.0;
double b = 1.0;
double c = 1.0;
Point center1,center2;
k = (p2.y - p1.y) / (p2.x - p1.x);
if(k == )
{
center1.x = (p1.x + p2.x) / 2.0;
center2.x = (p1.x + p2.x) / 2.0;
center1.y = p1.y + sqrt(dRadius * dRadius -(p1.x - p2.x) * (p1.x - p2.x) / 4.0);
center2.y = p2.y - sqrt(dRadius * dRadius -(p1.x - p2.x) * (p1.x - p2.x) / 4.0);
}
else
{
k_verticle = -1.0 / k;
mid_x = (p1.x + p2.x) / 2.0;
mid_y = (p1.y + p2.y) / 2.0;
a = 1.0 + k_verticle * k_verticle;
b = - * mid_x - k_verticle * k_verticle * (p1.x + p2.x);
c = mid_x * mid_x + k_verticle * k_verticle * (p1.x + p2.x) * (p1.x + p2.x) / 4.0 -
(dRadius * dRadius - ((mid_x - p1.x) * (mid_x - p1.x) + (mid_y - p1.y) * (mid_y - p1.y))); center1.x = (-1.0 * b + sqrt(b * b - * a * c)) / ( * a);
center2.x = (-1.0 * b - sqrt(b * b - * a * c)) / ( * a);
center1.y = Y_Coordinates(mid_x,mid_y,k_verticle,center1.x);
center2.y = Y_Coordinates(mid_x,mid_y,k_verticle,center2.x);
} fout << center1.x << " " << center1.y << endl;
fout << center2.x << " " << center2.y << endl;
} double Y_Coordinates(double x,double y,double k,double x0)
{
return k * x0 - k * x + y;
} bool Data_Validation(Point p1,Point p2,double dRadius)
{
double dDistance = 0.0;
dDistance = sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
if(dDistance == 0.0)
{
cout << "\n输入了相同的点!\n";
return false;
}
if(( * dRadius) >= dDistance)
return true;
else
{
cout << "\n两点间距离大于直径!\n";
return false;
}
} void ReadData(Point &p1,Point &p2,double &dRadius)
{
cout << "请输入圆周上一点的坐标:";
cin >> p1.x >> p1.y;
cout << "请输入圆周上另一点的坐标:";
cin >> p2.x >> p2.y;
cout << "请输入圆的半径:";
cin >> dRadius; if(! Data_Validation(p1,p2,dRadius))
{
cout << endl << "数据不合理!\n";
exit();
}
}

转 已知两点坐标和半径求圆心坐标程序C++的更多相关文章

  1. 【POJ 1981】Circle and Points(已知圆上两点求圆心坐标)

    [题目链接]:http://poj.org/problem?id=1981 [题意] 给你n个点(n<=300); 然后给你一个半径R: 让你在平面上找一个半径为R的圆; 这里R=1 使得这个圆 ...

  2. 已知两点的经度和纬度,计算两点间的距离(php,javascript)

    php代码:转载 http://www.cnblogs.com/caichenghui/p/5977431.html /** * 求两个已知经纬度之间的距离,单位为米 * * @param lng1 ...

  3. NX二次开发-UFUN已知两个向量方向求夹角角度UF_VEC3_angle_between

    NX9+VS2012 #include <uf.h> #include <uf_ui.h> #include <uf_vec.h> #include <uf_ ...

  4. 【C语言】已知三角形三边长,求三角形面积

    一. 数学基础: 已知三角形的三边,计算三角形面积,需要用到海伦公式: 即p=(a+b+c)/2 二. 算法: 输入三个边长,套用海伦公式计算面积,并输出. 可以先判断是否可以构成三角形,即任意两边之 ...

  5. js已知A,B两点坐标,在线段AB上有C点,已知AC的距离,求C点的坐标

    /** * @param {Number} _x1 A点坐标 * @param {Number} _y1 A点坐标 * @param {Number} _x2 B点坐标 * @param {Numbe ...

  6. Codeforce 459A - Pashmak and Garden (已知两点求另外两点构成正方形)

    Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashm ...

  7. 正方形已知两点对角线求另外两点(POJ2002)

    至于为什么,上图.转载于MZW_BG 枚举正方形的一条边,此时有上正方形和下正方形. 最后正方形个数/4,因为每个正方形被枚举了4条边 #include <bits/stdc++.h> u ...

  8. ACM题目————已知前序和中序求后序

    #include <iostream> #include <cstring> #include <cstdio> using namespace std; ], z ...

  9. 已知两点经纬度(百度地图),用js求解两点之间的角度

    采用的网址:https://my.oschina.net/boogoogle/blog/740478

随机推荐

  1. 【Mysql】 case ... when ... 用法

    sql语句查询时给某个空字段赋值 SELECT CASE WHEN field= '' THEN ' WHEN fieldIS NULL THEN ' ELSE field END FROM tabl ...

  2. Web和Native使用外部字体ttf方法

    论坛教程:http://bbs.egret.com/forum.php?mod=viewthread&tid=24879&extra=&highlight=%E5%AD%97% ...

  3. ehcache加载配置文件ehcache.xml的源码

    package net.sf.ehcache.config; public final class ConfigurationFactory { public static Configuration ...

  4. spring mvc的@Transactional注解

    转自:https://www.cnblogs.com/yepei/p/4716112.html spring的@Transactional注解详细用法   概述 事务管理对于企业应用来说是至关重要的, ...

  5. 【MySQL案例】error.log的Warning:If a crash happens thisconfiguration does not guarantee that the relay lo(转)

    标签: 1.1.1. If a crash happens thisconfiguration does not guarantee that the relay log info will be c ...

  6. intelliij jdea灰色文件处理办法

  7. centos7 安装后,出现Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]

    PS:出现以上信息,是要求你阅读或者接收协议: Initial setup of CentOS Linux 7 (core)解决步骤如下: 1,输入[1],按Enter键阅读许可协议,2,输入[2], ...

  8. HDU 1104 Remainder(BFS 同余定理)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1104 在做这道题目一定要对同余定理有足够的了解,所以对这道题目对同余定理进行总结 首先要明白计算机里的 ...

  9. spring boot web服务

    [root@d java]# tree -I target .├── pom.xml└── src ├── main │   ├── java │   │   └── com │   │   └── ...

  10. C# WinForm实现任务栏程序图标闪烁

    相信大家在用QQ的时候都会知道,你打开了QQ聊天窗口,如果窗口不是当前激活的窗口的话,收到QQ消息时,任务栏(不是托盘图标)上的图标会闪一下变成黄色(Win7默认主题下),用以通知用户有消息进来了,之 ...