Circle Through Three Points

本文介绍了一种通过三个平面上的点确定一个圆的算法。给出三个不在同一直线上的点的笛卡尔坐标,该算法可以计算出这些点确定的圆的方程,并将其表示为标准形式和一般形式。
部署运行你感兴趣的模型镜像
Circle Through Three Points

Your team is to write a program that, given the Cartesian coordinates of three points on a plane, will find the equation of the circle through them all. The three points will not be on a straight line. 
The solution is to be printed as an equation of the form 
	(x - h)^2 + (y - k)^2 = r^2				(1)

and an equation of the form 
	x^2 + y^2 + cx + dy - e = 0				(2)

Input
Each line of input to your program will contain the x and y coordinates of three points, in the order Ax, Ay, Bx, By, Cx, Cy. These coordinates will be real numbers separated from each other by one or more spaces.
Output
Your program must print the required equations on two lines using the format given in the sample below. Your computed values for h, k, r, c, d, and e in Equations 1 and 2 above are to be printed with three digits after the decimal point. Plus and minus signs in the equations should be changed as needed to avoid multiple signs before a number. Plus, minus, and equal signs must be separated from the adjacent characters by a single space on each side. No other spaces are to appear in the equations. Print a single blank line after each equation pair.
Sample Input
7.0 -5.0 -1.0 1.0 0.0 -6.0
1.0 7.0 8.0 6.0 7.0 -2.0
Sample Output
(x - 3.000)^2 + (y + 2.000)^2 = 5.000^2
x^2 + y^2 - 6.000x + 4.000y - 12.000 = 0

(x - 3.921)^2 + (y - 2.447)^2 = 5.409^2
x^2 + y^2 - 7.842x - 4.895y - 7.895 = 0
题目原网站: http://poj.org/problem?id=2260
       思路:只需通过数学计算,由三点求出圆心坐标,即可轻易得到半径,以及标准圆方程的展开方程各项系数。
       
圆心坐标计算:
   假设三点分别为(x1,y1),(x2,y2),(x3,y3),则圆心(x0,y0)可由以下公式计算得:

再将一个点带入圆心坐标方程,即可得到半径r,然后将圆心坐标方程展开的到一般方程,系数c=-2*h,d=-2*k,e=h^2+k^2-r^2;
输出时用条件表达式来控制符号。
代码:
#include<stdio.h>
#include<math.h>
int main() {
	double ax, ay, bx, by, cx, cy,a,b,c,d,e,f,h,k,r,cc,dd,ee;
	while ((scanf("%lf%lf%lf%lf%lf%lf", &ax, &ay, &bx, &by, &cx, &cy) != EOF)) {
		a = ax - bx; b = ay - by; c = ax - cx; d = ay - cy;
		e = ((ax*ax - bx*bx) - (by*by - ay*ay)) / 2;
		f = ((ax*ax - cx*cx) - (cy*cy - ay*ay)) / 2;
		h = -(d*e - b*f) / (b*c - a*d);
		k = -(a*f - c*e) / (b*c - a*d);
		r = (ax - h)*(ax - h) + (ay - k)*(ay - k);
		printf("(x %c %.3lf)^2 + (y %c %.3lf)^2 = %.3lf^2\n",
				h<0?'+':'-',h<0?-h:h,k<0?'+':'-',k<0?-k:k,sqrt(r));
		cc = -2 * h; dd = -2 * k; ee = h*h + k*k - r;
		printf("x^2 + y^2 %c %.3lfx %c %.3lfy %c %.3lf = 0\n\n",
			 cc < 0 ? '-' : '+', cc < 0 ? -cc : cc, dd < 0 ? '-' : '+', dd < 0 ? -dd : dd,
				 ee < 0 ? '-' : '+', ee < 0 ? -ee : ee);
	}
}


您可能感兴趣的与本文相关的镜像

Facefusion

Facefusion

AI应用

FaceFusion是全新一代AI换脸工具,无需安装,一键运行,可以完成去遮挡,高清化,卡通脸一键替换,并且Nvidia/AMD等显卡全平台支持

c++题目,代码禁止有注释 A Angry Birds 作者 刘春英 单位 杭州电子科技大学 Aris is playing the classic game, Angry Birds! Because Aris has been playing for too long, Yuuka confiscated Aris’s game console and demanded that Aris complete today’s math homework before getting it back. However, Sensei did not assign any math homework to Aris today, so Yuuka had to come up with a problem for Aris to solve. Consider the game field of Angry Birds as a three-dimensional Euclidean space, and the bird as a sphere with radius R 3 ​ . Establish a spatial Cartesian coordinate system O−xyz, such that the trajectory of the bird’s center lies in the horizontal plane z=0. It is known that the trajectory of the bird’s center is a closed polyline, consisting of n segments connected end to end. The connection points are n points: (x 1 ​ ,y 1 ​ ,0),(x 2 ​ ,y 2 ​ ,0),⋯,(x n ​ ,y n ​ ,0). The i-th segment has endpoints (x i ​ ,y i ​ ,0) and (x imodn+1 ​ ,y imodn+1 ​ ,0). However, due to sensor errors, the actual n points may deviate from (x i ​ ,y i ​ ,0) by a distance not exceeding R 2 ​ (the sensor deviation R 2 ​ is the same for all points). That is, the actual i-th point (x i ′ ​ ,y i ′ ​ ,0) can be anywhere within the circle (which is still contained in the plane z=0) centered at (x i ​ ,y i ​ ,0) with radius R 2. Let S be the set of all points that the entire bird may pass through, i.e., points in 3D space whose distance to the bird’s center trajectory is at most R 3 ​ . Yuuka requires Aris to compute the volume of the convex hull of S. Convex hull: The convex hull of a point set S is defined as the smallest set T such that for any two points in S, all points on the line segment between them are contained in T. Input Format The first line contains a positive integer T (1≤T≤10 3 ), indicating the number of test cases. For each test case, the first line contains three integers n,R 2 ​ ,R 3 ​ (1≤n≤10 5 ,0≤R 2 ​ ,R 3 ​ ≤10 6 ), representing the number of connection points, the sensor error radius, and the bird radius, respectively. The next n lines each contain two integers x i ​ ,y i ​ (∣x i ​ ∣,∣y i ​ ∣≤10 6 ), representing the i-th connection point of the trajectory. It is guaranteed that the sum of n over all test cases in a single test point does not exceed 10 5 . Output Format For each test case, output a single floating-point number representing answer. Your answer is considered correct if the relative or absolute error compared to the standard answer is at most 10 −9 . Let your answer be a and the standard answer be b. If max{b,1} ∣a−b∣ ​ ≤10 −9 , it is considered correct. Sample 1 5 1 1 0 0 3 1 2 3 2 2 -1 3 77.622211120429587 Notes The convex hull of all points that the bird’s center may pass through: sample.png 代码长度限制 32 KB Java (javac) 时间限制 2000 ms 内存限制 256 MB Python (python2) 时间限制 2000 ms 内存限制 256 MB Python (python3) 时间限制 2000 ms 内存限制 256 MB Python (pypy3) 时间限制 2000 ms 内存限制 256 MB Kotlin (kotlinc) 时间限制 2000 ms 内存限制 256 MB 其他编译器 时间限制 1000 ms 内存限制 256 MB 栈限制 131072 KB
最新发布
10-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值