HDU 2912

直线关于球的多次反射,求最后一次反射点

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>using namespace std;
const double inf=1e10;
const double eps=1e-8;
struct point {double x,y,z;
//    point (double _x,double _y,double _z){ x=_x; y=_y; z=_z; };
};
struct sphe {point cent;double r;
};
struct vect {point st,des;
};
sphe cir[110];vect livc;
int n;point operator -(const point &u,const point &v){point ret;ret.x=u.x-v.x; ret.y=u.y-v.y; ret.z=u.z-v.z;return ret;
}double dot(point x,point y){return x.x*y.x+x.y*y.y+x.z*y.z;
}point xmulti(point u,point v){point ret;ret.x=(u.y*v.z-v.y*u.z);ret.y=(u.z*v.x-u.x*v.z);ret.z=(u.x*v.y-u.y*v.x);return ret;
}double dis(point x,point y){return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y)+(x.z-y.z)*(x.z-y.z));
}double vlen(point x){return sqrt(x.x*x.x+x.y*x.y+x.z*x.z);
}point  construct(){point crop;crop.x=crop.y=crop.z=0;double stoc=inf; point tmpcrop; point foot,tmpfoot; bool flag; point tmp; int k;while(true){flag=false; stoc=inf;for(int i=0;i<n;i++){if(dot(livc.des-livc.st,cir[i].cent-livc.st)>=-eps){//判断圆是否与直线同向,通过点积判方向 double D=vlen(xmulti(livc.des-livc.st,cir[i].cent-livc.st))/dis(livc.st,livc.des);  //    cout<<D<<' '<<i<<endl;if(D-cir[i].r<=eps){       //半径小于D,相交 flag=true;//    cout<<"YES"<<endl;double u=dot(cir[i].cent-livc.st,livc.des-livc.st)/(dis(livc.st,livc.des)*dis(livc.st,livc.des));//计算垂足。可通过向量的比例所得方程,联合垂直点积为0的方程解得 tmpfoot=livc.st;tmpfoot.x+=u*(livc.des.x-livc.st.x);tmpfoot.y+=u*(livc.des.y-livc.st.y);tmpfoot.z+=u*(livc.des.z-livc.st.z);//    cout<<tmpfoot.x<<' '<<tmpfoot.y<<' '<<tmpfoot.z<<' '<<endl;u=sqrt((cir[i].r*cir[i].r-D*D))/dis(livc.st,livc.des);  //计算交点。垂足到圆上交点方向与直线反方向相同//通过两者距离比计算出向量的转化 tmpcrop=tmpfoot;tmp=livc.st-livc.des;tmpcrop.x+=tmp.x*u;tmpcrop.y+=tmp.y*u;tmpcrop.z+=tmp.z*u;D=dis(tmpcrop,livc.st);//    cout<<D<<endl;if(D<stoc){     //若与多个圆相交,选取较近的一个 stoc=D; crop=tmpcrop;k=i;}}}}if(!flag) return crop;double tu=dot(livc.st-cir[k].cent,crop-cir[k].cent)/(dis(crop,cir[k].cent)*dis(crop,cir[k].cent));tmpfoot=cir[k].cent;     //计算反射线。直线st点关于交点与球心的直线 对称点作为反射线的des点 tmpfoot.x+=tu*(crop.x-cir[k].cent.x);tmpfoot.y+=tu*(crop.y-cir[k].cent.y);tmpfoot.z+=tu*(crop.z-cir[k].cent.z);    //知直线st点到反射线des点的方向与st点到关于对称线垂足方向相同且为两倍 livc.des.x=((tmpfoot.x-livc.st.x)*2+livc.st.x);  //通过这样可以求对称点 livc.des.y=((tmpfoot.y-livc.st.y)*2+livc.st.y);livc.des.z=((tmpfoot.z-livc.st.z)*2+livc.st.z);livc.st=crop;//    cout<<livc.des.x<<' '<<livc.des.x<<' '<<livc.des.x<<endl;}
}int main(){point tmp; double r;while(scanf("%d",&n),n){livc.st.x=livc.st.y=livc.st.z=0;scanf("%lf%lf%lf",&tmp.x,&tmp.y,&tmp.z);livc.des=tmp;for(int i=0;i<n;i++){scanf("%lf%lf%lf%lf",&cir[i].cent.x,&cir[i].cent.y,&cir[i].cent.z,&cir[i].r);}tmp=construct();printf("%.4lf %.4lf %.4lf\n",tmp.x,tmp.y,tmp.z);}
}

  

转载于:https://www.cnblogs.com/jie-dcai/p/3902389.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/273633.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

EMVTag系列3《持卡人基本信息数据》

9F61 持卡人证件号 L&#xff1a;2–26 R&#xff08;需求&#xff09;&#xff1a;数据应存在&#xff0c;在读应用数据过程中&#xff0c;终端不检查&#xff1b; (PBOC2.0第五部分中规定)芯片中持卡人姓名 5F20与持卡人姓名扩展9F0B只能使用一个&#xff0c;另一个必须不…

BindingException: Parameter 'XXX' not found. Available parameters are [collection, list]

应业务需求&#xff0c;需要使用到MQ进行数据上传和下发。传递格式为JSON,服务那边下发JSON数组&#xff0c;接收端将JSON数组转换成List集合&#xff0c;调用Mybatis-plus批量添加saveBatch()。提示字段未找到... org.apache.ibatis.exceptions.PersistenceException: ### Er…

JDK 8 新特性 之 default关键字

前言 Jdk1.8之前的接口中只声明方法&#xff0c;方法具体实现应在子类中进行。Jdk1.8打破了这样的用法&#xff1a;接口中可以实现具体的方法体&#xff0c;只需要加上关键字static或者default修饰即可。 default关键字 public interface UserService {//自定义方法void getUse…

headroom.js插件使用方法

1.什么是headroom.js&#xff1f; headroom是用纯Javascript写的插件&#xff0c;用来隐藏和展示页面元素&#xff0c;从而为页面留下更多空间。比如使用headroom能使导航栏当页面下滚时消失&#xff0c;当页面上滚时候又出现。&#xff08;查看效果&#xff09; 2.工作原理 通…

JDK 8 新特性 之 方法引用

概述 方法引用&#xff1a;当要传递给Lambda体的操作&#xff0c;已经有实现的方法了&#xff0c;就可以使用方法引用方法引用&#xff1a;在Lambda的基础上进一步的简化。换句话说&#xff0c;方法引用就是Lambda表达式&#xff0c;也就是函数式接口的一个实例&#xff0c;通过…

项目记录:springmvc forward redirect 问题

RequestMapping("/redirect")public String redirect(RedirectAttributes redirectAttributes){redirectAttributes.addFlashAttribute("test", "testdata"); //专供此种情况下使用。return "redirect:read";} 注意&#xff1a;此种情…

JDK 8 新特性 之 Lambda表达式

前言 Lambda 表达式&#xff0c;也可称为闭包&#xff0c;它是推动 Java 8 发布的最重要新特性。Lambda 允许把函数作为参数传递进方法中。使用 Lambda 表达式可以使代码变的更加简洁紧凑。lambda表达式的重要特征: 可选类型声明&#xff1a;不需要声明参数类型&#xff0c;编译…

开源组件DocX导出Word

1、使用Docx替换Word模板里书签里内容的一个方法 using Novacode;public class ExportWord{/// <summary>/// 导出word/// </summary>/// <param name"lBookMarks">书签数据源</param>/// <param name"sTemplatePath">导出W…

JDK 8 新特性 之 Strams简单使用

概述 Java 8 API添加了一个新的抽象称为流Stream&#xff0c;可以让你以一种声明的方式处理数据。 Stream 使用一种类似用 SQL 语句从数据库查询数据的直观方式来提供一种对 Java 集合运算和表达的高阶抽象。 Stream API可以极大提供Java程序员的生产力&#xff0c;让程序员写出…

Cannot open include file: jni.h: No such file or directory解决方法

在此运行Visual Studio 2012 项目时出现 #include <stdio.h> #include <jni.h> int main() { printf("Hello World"); } But when I try to build, I get the following error - 1>c:testtest.cpp(2) : fatal error C1083: Cannot open include file:…

JDK 8 新特性 之 函数接口

函数接口 定义:接口中只有唯一的一个抽象方法&#xff0c;该接口就称之为函数接口。 //函数接口 public interface FunctionInterface1 {//1、只有一个方法的接口&#xff0c;默认称之为函数接口void get(); }//非函数接口 public interface FunctionInterface2 {void get1();v…

微服务之基础知识

什么是微服务架构 微服务是系统架构上的一种设计风格&#xff0c; 它的主旨是将一个原本独立的系统拆分成多个小型服务&#xff0c;这些小型服务都在各自独立的进程中运行&#xff0c;服务之间通过基于HTTP的RESTful API进行通信协作。 被拆分成的每一个小型服务都围绕着系统中…

LightOj 1078 Basic Math

思路&#xff1a; 设输入的两个数分别为n和a,每一次所得到的数为update&#xff1a; 开始updatea,依次update分别为update*10a,这样数据会超出范围&#xff0c;则update每次为update(update*10a)%n即可&#xff0c; 如果update0,跳出循环&#xff1b; 只需证明&#xff1a;(upd…

还是俄罗斯方块之android版

前面的&#xff0c;口水话 请直接跳过。 虽然现在不比以前了 也没多少人气了&#xff0c;放到首页 都不到几百的点击量。也许博客园整体水平也是在往水的方向发展。不谈那些了&#xff0c;哥也曾经辉煌过 有过一天上千的点击量 &#xff0c;哥也曾经有过粉丝&#xff0c;被小妹…

Integer 值判断相等

Integer 值判断相等 案例&#xff1a; public class Test {public static void main(String[] args) {Integer a 127;Integer b 127;System.out.println("a b :" (a b));System.out.println("a.equals(b):"a.equals(b));String x "127";Str…

自定义快捷命令程序(VC++加批处理)

一 概述 在看《从小工到专家-程序员修炼之道》时&#xff0c;看到建议使用Shell&#xff0c;很有感触。在很多时候&#xff0c;通过键盘操作&#xff0c;比鼠标的确会块很多&#xff0c;如果能用好shell命令&#xff08;或批处理命令&#xff09; &#xff0c;的确能节省我们…

Redis 快速入门

简介 Redis 是一个 Key-Value 存储系统。和 Memcached 类似&#xff0c;它支持存储的 value 类型相对更多&#xff0c;包括 string(字符串)、 list(链表)、 set(集合)和 zset(有序集合)。这些数据类型都支持 push/pop、add/remove 及取交集并集和差集及更丰富的操作&#xff0c…

7. Adapter

转载于:https://www.cnblogs.com/anit/p/3930202.html

Redis 中常用命令

Redis 中常用命令 keys 返回满足给定 pattern 的所有 key。 127.0.0.1:6379> keys *1) "name2"2) "myzset"3) "myset7"4) "name"5) "myset6"6) "mylist"7) "mylist2"8) "myset3"9) "…

CGI与Servlet的区别和联系

1. 定义&#xff1a; CGI(Common Gateway Interface 公共网关接口)是HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具&#xff0c;其程序须运行在网络服务器上。 2. 功能&#xff1a; 绝大多数的CGI程序被用来解释处理杰自表单的输入信息&#xff0c;并在服 务器产生…