hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)
Mirror and Light
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 650 Accepted Submission(s): 316
Now, our problem is that, if a branch of light goes into a large and infinite mirror, of course,it will reflect, and leave away the mirror in another direction. Giving you the position of mirror and the two points the light goes in before and after the reflection, calculate the reflection point of the light on the mirror.
You can assume the mirror is a straight line and the given two points can’t be on the different sizes of the mirror.
The following every four lines are as follow:
X1 Y1
X2 Y2
Xs Ys
Xe Ye
(X1,Y1),(X2,Y2) mean the different points on the mirror, and (Xs,Ys) means the point the light travel in before the reflection, and (Xe,Ye) is the point the light go after the reflection.
The eight real number all are rounded to three digits after the decimal point, and the absolute values are no larger than 10000.0.
0.000 0.000
4.000 0.000
1.000 1.000
3.000 1.000
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
struct Point {double x,y;}; //点
struct Ldir{double dx,dy;}; //方向向量
struct Lline{Point p; Ldir dir;}; //直线
// 计算直线的一般式 Ax+By+C=0
void format(Lline ln,double& A,double& B,double& C)
{
A=ln.dir.dy;
B=-ln.dir.dx;
C=ln.p.y*ln.dir.dx-ln.p.x*ln.dir.dy;
}
// 求点p1关于直线ln的对称点p2
Point mirror(Point P,Lline ln)
{
Point Q;
double A,B,C;
format(ln,A,B,C);
Q.x=((B*B-A*A)*P.x-*A*B*P.y-*A*C)/(A*A+B*B);
Q.y=((A*A-B*B)*P.y-*A*B*P.x-*B*C)/(A*A+B*B);
return Q;
}
//求线段交点
struct TLine
{
//直线标准式中的系数
double a, b, c;
};
TLine lineFromSegment(Point p1, Point p2)
{
TLine tmp;
tmp.a = p2.y - p1.y;
tmp.b = p1.x - p2.x;
tmp.c = p2.x * p1.y - p1.x * p2.y;
return tmp;
}
/*求直线的交点,注意平形的情况无解,避免RE*/
const double eps = 1e-; //注意一定要加,否则错误
Point LineInter(TLine l1, TLine l2)
{
//求两直线得交点坐标
Point tmp;
double a1 = l1.a;
double b1 = l1.b;
double c1 = l1.c;
double a2 = l2.a;
double b2 = l2.b;
double c2 = l2.c;
//注意这里b1 = 0
if(fabs(b1) < eps){
tmp.x = -c1 / a1;
tmp.y = (-c2 - a2 * tmp.x) / b2;
}
else{
tmp.x = (c1 * b2 - b1 * c2) / (b1 * a2 - b2 * a1);
tmp.y = (-c1 - a1 * tmp.x) / b1;
}
return tmp;
}
int main()
{
int T;
cin>>T;
cout<<setiosflags(ios::fixed)<<setprecision();
while(T--){
Point p1,p2,ps,pe;
Lline l;
cin>>p1.x>>p1.y;
cin>>p2.x>>p2.y;
cin>>ps.x>>ps.y;
cin>>pe.x>>pe.y;
l.p = p1;
l.dir.dx = p2.x - p1.x;
l.dir.dy = p2.y - p1.y;
Point duichen = mirror(ps,l); //求对称点
//cout<<duichen.x<<' '<<duichen.y<<endl;
TLine l1,l2;
l1 = lineFromSegment(p1,p2);
l2 = lineFromSegment(duichen,pe);
Point inter = LineInter(l1,l2); //求交点
cout<<inter.x<<' '<<inter.y<<endl;
}
return ;
}
Freecode : www.cnblogs.com/yym2013
hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)的更多相关文章
- HDU 2857 Mirror and Light
/* hdu 2857 Mirror and Light 计算几何 镜面反射 */ #include<stdio.h> #include<string.h> #include& ...
- 「HDU - 2857」Mirror and Light(点关于直线的对称点)
题目链接 Mirror and Light 题意 一条直线代表镜子,一个入射光线上的点,一个反射光线上的点,求反射点.(都在一个二维平面内) 题解 找出入射光线关于镜子直线的对称点,然后和反射光线连边 ...
- Gym-101915B Ali and Wi-Fi 计算几何 求两圆交点
题面 题意:给你n个圆,每个圆有一个权值,你可以选择一个点,可以获得覆盖这个点的圆中,权值最大的m个的权值,问最多权值是多少 题解:好像是叙利亚的题....我们画画图就知道,我们要找的就是圆与圆交的那 ...
- hdu 2857 点在直线上的投影+直线的交点
Mirror and Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1086:You can Solve a Geometry Problem too(计算几何,判断两线段相交,水题)
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- sgu 129 Inheritance 凸包,线段交点,计算几何 难度:2
129. Inheritance time limit per test: 0.25 sec. memory limit per test: 4096 KB The old King decided ...
- hdu 1147:Pick-up sticks(基本题,判断两线段相交)
Pick-up sticks Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1171 Big Event in HDU【01背包/求两堆数分别求和以后的差最小】
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 2393:Higher Math(计算几何,水题)
Higher Math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- OE context 传参数
来自:http://shine-it.net/index.php/topic,16360.0.html 有个需求想many2one字段关联显示的value在各个模块显示不同的值. 如果直接该rel_n ...
- 如何阅读Android系统源码-收藏必备
对于任何一个对Android开发感兴趣的人而言,对于android系统的学习必不可少.而学习系统最佳的方法就如linus所言:"RTFSC"(Read The Fucking So ...
- windows bat文件运行中文乱码
windows bat文件运行中文乱码 CreationTime--2018年7月17日08点51分 Author:Marydon 1.情景展示 运行bat文件,里面的中文提示显示乱码 2.问题剖 ...
- linux 挂载 ISO 文件
sudo sudo mount -o loop SUSE-Linux-10.1-GM-DVD-x86_64.iso /media/cdrom/ sudo umount /media/cdrom
- Session 简单购物车
package session.test; import java.io.IOException; import java.io.PrintWriter; import java.util.Linke ...
- unity模型任意无限切割插件
概述 3d模型的任意切割一直是游戏开发里的一个很大的问题,模型切割的关键点就只有生成横切面的新顶点以及切口纹理的缝合,理论上解决了这两点,就近乎可以做到以假乱真的程度了.本篇文章就这两点进行描述 详细 ...
- 音视频技术 即时通讯SDK
视频流中的DTS/PTS究竟是什么? DTS(解码时间戳)和PTS(显示时间戳)各自是解码器进行解码和显示帧时相对于SCR(系统參考)的时间戳.SCR能够理解为解码器应该開始从磁盘读取数据时 ...
- Java中Math类的几个四舍五入方法的区别
JAVA取整以及四舍五入 下面来介绍将小数值舍入为整数的几个方法:Math.ceil().Math.floor()和Math.round(). 这三个方法分别遵循下列舍入规则:Math.ceil()执 ...
- atitit.获取connection hibernate4
atitit.获取connection hibernate4 1. SessionFactoryUtils法(推荐) 1 2. ConnectionProvider 法( ) 1 3. 嘎自实现法(不 ...
- angular学习疑问总结
服务里返回的数据是不是只能传给控制器,而不能传给指令呢?如果是的话那么指令只能通过配置scope属性来访问控制器里的数据