HDU 2857 镜面反射
来源:互联网 发布:网络骑士全部作品 编辑:程序博客网 时间:2024/04/30 11:16
给你镜子的位置(用两点确定的一条直线表示),光源,光的反射点,求光在镜子的折射点。
初中常做的题目。
const double eps = 1e-8 ;double sig(double x){ if(fabs(x) < eps) return 0 ; return x > 0 ? 1 : -1 ;}double add(double x , double y){ if(fabs(x+y) < eps*(fabs(x) + fabs(y))) return 0 ; return x + y ;}struct Point{ double x , y ; Point(){} Point(double _x , double _y):x(_x),y(_y){} Point operator + (Point o){ return Point(add(x , o.x) , add(y , o.y)) ; } Point operator - (Point o){ return Point(add(x , -o.x) , add(y , -o.y)) ; } Point operator * (double o){ return Point(x*o , y*o) ; } double operator ^(Point o){ return add(x*o.y , -y*o.x) ; } double dist(Point o){ return sqrt((x-o.x)*(x-o.x) + (y-o.y)*(y-o.y)) ; } void read(){ scanf("%lf%lf" ,&x , &y) ; }};//直线p1p2 与直线q1q2 的交点Point getintersect(Point p1 , Point p2 , Point q1 , Point q2){ double d1 = (p2 - p1) ^ (q1 - p1) ; double d2 = (p2 - p1) ^ (q2 - q1) ; double d3 = (q2 - q1) ^ (q1 - p1) ; double d4 = (q2 - q1) ^ (p2 - p1) ; if(fabs(d1) < eps) return q1 ; if(fabs(d2) < eps) return q2 ; double t = d3 / d4 ; return p1 + (p2 - p1) * t ;}struct Line{ Point s , t ; Line(){} Line(Point _s , Point _t):s(_s),t(_t){} Point getinterpoint(Line o){ return getintersect(s , t , o.s , o.t) ; } Point mindistpoint(Point p){//p到直线的垂点 Point p1 = p ; Point p2 = p + Point(s.y - t.y , t.x - s.x) ; return getintersect(p1 , p2 , s , t) ; } void read(){ s.read() , t.read() ; }} ;int main(){ int i , j , t ; Line mirror ; Point a , b , c , _a , s ; cin>>t ; while(t--){ mirror.read() ; a.read() ; b.read() ; c = mirror.mindistpoint(a) ; //垂点 _a = c * 2 - a ; //a关于镜子的对称点_a s = mirror.getinterpoint(Line(_a , b)) ; printf("%.3lf %.3lf\n" , s.x , s.y) ; } return 0 ;}
0 0
- HDU 2857 镜面反射
- opengl镜面反射
- Unity:镜面反射
- Unity3D 镜面反射
- Unity3D--镜面反射
- Unity3D 镜面反射
- Unity3D镜面反射
- Unity:镜面反射
- 镜面反射
- Unity 镜面反射
- 镜面反射
- 制作镜面反射脚本
- shader镜面反射(Reflection)
- HLSL实现镜面反射光照模型
- u3d 镜面反射的效果
- HLSL实现镜面反射光照模型
- 镜面反射与Phong模型
- 光照阴影镜面反射综合算法
- 参赛总结
- jquery $(document).ready() 与window.onload的区别
- 使用Swift创建Swift模块 - 静态链接库
- js事件防止冒泡
- poj 3233 Matrix Power Series
- HDU 2857 镜面反射
- 泛珠三角比赛项目总结
- 美国IT公司的公司文化(1)
- 在Swift中使用CocoaPods
- [深度优先]求迷宫中包含最多珠宝的路径
- 美国IT公司的公司文化(2)
- uva 10515 - Powers Et Al.(数论)
- 银行业务调度系统学习
- 关于Tomcat 不能识别 Eclipse工作区间 Java web 工程