Sicily1059-Exocenter of a Trian
2015-11-13 18:11
387 查看
代码地址: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1059.c
On each side of ABC, construct a square (ABDE, BCHJ and ACFG in the figure below).
Connect adjacent square corners to form the three Extriangles (AGD, BEJ and CFH in the figure).
The Exomedians of ABC are the medians of the Extriangles, which pass through vertices of the original triangle, extended into the original triangle (LAO, MBO and NCO in the figure. As the figure indicates, the three Exomedians intersect at a common point called the Exocenter (point O in the figure).
This problem is to write a program to compute the Exocenters of triangles.
这题首先最重要的一点: 证明我们要求解的就是三角形ABC的垂心的坐标。
证明如下:
证明:
∵AK = A'K DK = GK ∠6 = ∠7
根据(SAS) ∴△AGK≌A'GK
∴∠1 = ∠4
又∵∠1 + ∠2 + ∠3 = 180°
∴∠2 + ∠3 + ∠4 = 180°
又∵∠3 + ∠4 + ∠5 = 180°
∴∠2 = ∠5
又∵AD = AB AG = AC
根据SAS ∴△ABC≌DAA'
∴∠3 = ∠8
又∵∠BAO + ∠3 = 90°
∴∠BAO + ∠8 = 90°
∴∠9 = 90°
同理∠10 = ∠11 = 90°
∴点O为高线交点 为△ABC的垂心
证毕。
好, 接下来是垂心的求解思路,很简单,设垂心坐标为(x, y), 三角形3个点坐标为(x1, y1) (x2, y2) (x3, y3)
用向量垂直来得到以下公式:
(x2 - x1)(x - x3) + (y2 - y1)(y - y3) = 0
(x3 - x1)(x - x2) + (y3 - y1)(y - y2) = 0
然后就求解这个方程组得到x, y就行了
但是这么做会有两个坑:
1. 不能输出-0.0000 所以最后结果输出的时候+个EPS就可以了。
2. 用向量计算的时候计算出x, 在计算y的时候,如果这时候使用的直线是平行于y轴的, 带入x将会输出错误的结果, 此时应换另一个直线方程做计算。
AC代码:
1059. Exocenter of a Trian
Constraints
Time Limit: 1 secs, Memory Limit: 32 MBDescription
Given a triangle ABC, the Extriangles of ABC are constructed as follows:On each side of ABC, construct a square (ABDE, BCHJ and ACFG in the figure below).
Connect adjacent square corners to form the three Extriangles (AGD, BEJ and CFH in the figure).
The Exomedians of ABC are the medians of the Extriangles, which pass through vertices of the original triangle, extended into the original triangle (LAO, MBO and NCO in the figure. As the figure indicates, the three Exomedians intersect at a common point called the Exocenter (point O in the figure).
This problem is to write a program to compute the Exocenters of triangles.
Input
The first line of the input consists of a positive integer n, which is the number of datasets that follow. Each dataset consists of 3 lines; each line contains two floating point values which represent the (two -dimensional) coordinate of one vertex of a triangle. So, there are total of (n*3) + 1 lines of input. Note: All input triangles wi ll be strongly non-degenerate in that no vertex will be within one unit of the line through the other two vertices.Output
For each dataset you must print out the coordinates of the Exocenter of the input triangle correct to four decimal places.这题首先最重要的一点: 证明我们要求解的就是三角形ABC的垂心的坐标。
证明如下:
证明:
∵AK = A'K DK = GK ∠6 = ∠7
根据(SAS) ∴△AGK≌A'GK
∴∠1 = ∠4
又∵∠1 + ∠2 + ∠3 = 180°
∴∠2 + ∠3 + ∠4 = 180°
又∵∠3 + ∠4 + ∠5 = 180°
∴∠2 = ∠5
又∵AD = AB AG = AC
根据SAS ∴△ABC≌DAA'
∴∠3 = ∠8
又∵∠BAO + ∠3 = 90°
∴∠BAO + ∠8 = 90°
∴∠9 = 90°
同理∠10 = ∠11 = 90°
∴点O为高线交点 为△ABC的垂心
证毕。
好, 接下来是垂心的求解思路,很简单,设垂心坐标为(x, y), 三角形3个点坐标为(x1, y1) (x2, y2) (x3, y3)
用向量垂直来得到以下公式:
(x2 - x1)(x - x3) + (y2 - y1)(y - y3) = 0
(x3 - x1)(x - x2) + (y3 - y1)(y - y2) = 0
然后就求解这个方程组得到x, y就行了
但是这么做会有两个坑:
1. 不能输出-0.0000 所以最后结果输出的时候+个EPS就可以了。
2. 用向量计算的时候计算出x, 在计算y的时候,如果这时候使用的直线是平行于y轴的, 带入x将会输出错误的结果, 此时应换另一个直线方程做计算。
AC代码:
#include <cstdio> #include <cmath> #define EPS 1e-8 int main() { int t; double x1, y1, x2, y2, x3, y3, x, y; scanf("%d", &t); while (t--) { scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3); x = (x3 * (x2 - x1) * (y3 - y1) - (y2 - y1) * ((x3 - x1) * x2 + (y2 - y3) * (y3 - y1))) / ((x2 - x1) * (y3 - y1) + (y2 - y1) * (x1 - x3)); y = (fabs(x - x3) < EPS) ? y2 + (x3 - x1) * (x - x2) / (y1 - y3) : y3 + (x2 - x1) * (x - x3) / (y1 - y2); printf("%.4f %.4f\n", x + EPS, y + EPS); } return 0; }
相关文章推荐
- C++primer--lambda表达式-参数绑定之bind
- Objective-c 协议(protocol)
- spa
- 生成随机字母字符串(数字字母混和)
- Linq To Objective-C
- maven包冲突问题 org.apache.catalina.LifecycleException: Failed to start component ,org.springframework.w
- Android拨打电话Intent.ACTION.CALL
- mysql 时间戳 与 日期类型的转换
- 代码:css3动画效果demo
- 项目冲刺-第三天
- QQl聊天消息
- Ajax 服务器返回html字符串中元素的事件绑定方法
- webshell定时器与CAS单点冲突的奇葩问题
- 维度模型数据仓库(十五) —— 多重星型模式
- 实例说明策略模式
- SVD 与 PCA 的直观解释 && 径向基(Radial basis function)神经网络、核函数的一些理解
- 调试碰到问题小计
- app配置智能硬件的解决方案
- C提高_day03_二级指针做输入第2种内存模型
- Cassandra教程(3)---- 架构理念