题目链接:http://poj.org/problem?id=3813
Time Limit: 1000MS Memory Limit: 65536K

Description

In one of his notebooks, Euclid gave a complex procedure for solving the following problem. With computers, perhaps there is an easier way.

In a 2D plane, consider a line segment AB, another point C which is not collinear with AB, and a triangle DEF. The goal is to find points G and H such that:

H is on the ray AC (it may be closer to A than C or further away, but angle CAB is the same as angle HAB) 
ABGH is a parallelogram (AB is parallel to HG, AH is parallel to BG) 
The area of parallelogram ABGH is the same as the area of triangle DEF

Input

There will be several test cases. Each test case will consist of twelve real numbers, with no more than 3 decimal places each, on a single line. Those numbers will represent, in order:

AX AY BX BY CX CY DX DY EX EY FX FY

where point A is (AX,AY), point B is (BX,BY), and so on. Points A, B and C are guaranteed to NOT be collinear. Likewise, D, E and F are also guaranteed to be non-collinear. Every number is guaranteed to be in the range from -1000.0 to 1000.0 inclusive. End of the input will be signified by a line with twelve 0.0's.

Output

For each test case, print a single line with four decimal numbers. These represent points G and H, like this:

GX GY HX HY

where point G is (GX,GY) and point H is (HX,HY). Print all values rounded to 3 decimal places of precision (NOT truncated). Print a single space between numbers. Do not print any blank lines between answers.

Sample Input

0 0 5 0 0 5 3 2 7 2 0 4
1.3 2.6 12.1 4.5 8.1 13.7 2.2 0.1 9.8 6.6 1.9 6.7
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

Sample Output

5.000 0.800 0.000 0.800
13.756 7.204 2.956 5.304

Problem solving report:

Description: 找到点G和H使得:H在射线AC上、ABGH是平行四边形,且平行四边形ABGH的面积与三角形DEF的面积相同
Problem solving: 先求出DEF的面积,就可以得到平行四边形ABGH的高,即点H到AB的距离,然后再通过求三角形ABC的面积求出点C到AB的距离,通过点H到AB的距离与点C到AB的距离就可以求得AH的距离,然后利用射线AC即可求出点H和点G。注意利用叉乘求面积的时候要带上绝对值。。。

Accepted Code:

/* * @Author: lzyws739307453 * @Language: C++ */
#include <math.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef struct point {double x, y;point(){}point(double x_, double y_) : x(x_), y(y_) {}
}vect;
point A, B, C, D, E, F, G, H;
double Cross(vect a, vect b) {return a.x * b.y - a.y * b.x;
}
vect operator - (const point a, const point b) {return vect(a.x - b.x, a.y - b.y);
}
double Area(point a, point b, point c) {return fabs(Cross(b - a, c - a)) / 2;
}
int main() {while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y, &D.x, &D.y, &E.x, &E.y, &F.x, &F.y) != EOF) {if (!A.x && !A.y && !B.x && !B.y && !C.x && !C.y && !D.x && !D.y && !E.x && !E.y)break;double par = Area(A, B, C) * 2;double triangle = Area(D, E, F);double rate = triangle / par;H.x = A.x + rate * (C.x - A.x);H.y = A.y + rate * (C.y - A.y);G.x = B.x + H.x - A.x;G.y = B.y + H.y - A.y;printf("%.3lf %.3lf %.3lf %.3lf\n", G.x, G.y, H.x, H.y);}return 0;
}

POJ - Euclid(计算几何)相关推荐

  1. [Poj 2187] 计算几何之凸包(二) {更高效的算法}

    { 承上一节 继续介绍点集的凸包  (下文中所有凸包 若不做特殊说明均指点集的凸包) 这一节介绍相比更高效的算法 } ========================================= ...

  2. POJ 2954-Triangle(计算几何+皮克定理)

    题目地址:POJ 2954 题意:给出三角形的三个顶点,求内部格点的个数. 思路:形同POJ 1265. #include <stdio.h> #include <math.h> ...

  3. POJ 1265-Area(计算几何+皮克定理+多边形面积公式)

    题目地址:POJ 1265 题意:给定一个格点多边形,求出内部点数in,边上点数on,和面积S. 思路:运用的定理很多. 1.皮克定理:S=in+on/2-1,即in=(2*S+2-on)/2. 2. ...

  4. POJ 1584 计算几何 凸包

    链接: http://poj.org/problem?id=1584 题意: 按照顺时针或逆时针方向输入一个n边形的顶点坐标集,先判断这个n边形是否为凸包. 再给定一个圆形(圆心坐标和半径),判断这个 ...

  5. poj 1269 计算几何

    题意:此题要处理给定的四个点,前两个点,后两个点分别构成一条直线,判断这两条直线是否重合,平行,相交,若相交,给出交点. 解题思路:可以用向量叉积判断是否重合和平行 重合:设第一个点和第二个点构成向量 ...

  6. POJ 3855 计算几何·多边形重心

    思路: 多边形面积->任选一个点,把多边形拆成三角,叉积一下 三角形重心->(x1+x2+x3)/3,(y1+y2+y3)/3 多边形重心公式题目中有,套一下就好了 计算多边形重心方法: ...

  7. POJ 3525(计算几何+凸多边形最大内切圆)

    问题描述: The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it ...

  8. [kuangbin]各种各样的题单

    [kuangbin]各种各样的题单 专题1 简单搜索 POJ 1321 POJ 2251 POJ 3278 POJ 3279 POJ 1426 POJ 3126 POJ 3087 POJ 3414 F ...

  9. POJ 计算几何入门题目推荐

      其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中.之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的算法,在很多领域有着重要的用途(例如本人的专 ...

最新文章

  1. 开发实习生做什么_实习生月薪6W,还有住房补贴!投行前台到底是做什么的?...
  2. linux驱动双摄像头,详解linux 摄像头驱动编写
  3. c# 给文件/文件夹 管理用户权限
  4. MapReduce运行机制-Reduce阶段
  5. 漫画:什么是拜占庭将军问题
  6. 中科院等发布《2019研究前沿》
  7. Python中利用LSTM模型进行时间序列预测分析
  8. php 修改input内容,JS简单获取并修改input文本框内容的方法示例
  9. invalid comparison: java.util.Date and java.lang.String
  10. volist 自增序号 分页如何实现?
  11. js读取excel表格
  12. 基于微信校园跑腿小程序毕业设计设计与实现毕设参考
  13. linux centos dhcpd进程,centos7 – 如何在Centos 7上忽略dhcpd中未使用的网络接口
  14. flex实现三栏布局
  15. Git Branching
  16. 功能测试 —— TPShop商城项目
  17. JUnit测试提示 java.lang.Exception: No public static parameters method on class
  18. Cesium更换地球背景
  19. 百面机器学习01-特征工程
  20. Processing 网格纹理制作(棋盘格)

热门文章

  1. C++求两个集合的交集
  2. 东北大学软件项目管理与过程改进复习提纲(2020)——第五章《项目范围管理》
  3. 常见的主流浏览器内核
  4. Github桌面版使用方式
  5. 计算2的100次方模5的结果
  6. 对计算机科技的理解,对现代教育技术的认识和理解
  7. STM32-GPIO介绍
  8. DVD/CD-ROM驱动器感叹号解决方法
  9. python3 beautiful爬取安居客的二手房信息
  10. Dynamic Potential-Based Reward Shaping将势能塑形奖励函数拓展为F(s,t,s‘,t‘)