SGU110 Computational Geometry

Source: Internet
Author: User

Question: N sphere in a three-dimensional space. Give a beam direction and find the reflection (spherical reflection) between these sphere ).

Problem: N spheres are in a 3D-space. give you a ction of a light and write a program to output the reflections (the light rays reflect from the surface of the spheres according the ordinary law ).

Question: As shown in, each reflection is divided into two steps. The first step is to use the link in the graph to find the tt and then the reflection point. Step 2 use the Projection Theorem to obtain the direction vector of the reflected light.

Solutions: As shown in the figure, each reflection can be considered as two steps. firstly, calculate the value of tt according to the figure, then make the reflect point. secondly, calculate the direction vector of the reflected ray by the projection theorem.


#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include using namespace std;#define P(x) ((x)*(x))const int N=50+10;const double oo=(1LL<<60);const double eps=1e-8;int n,cnt;double r[N],tt;struct Point {    Point() {}    Point(double x,double y,double z): x(x),y(y),z(z) {}    double x,y,z;}c[N],s,e,dir;double operator *(Point A,Point B) {return A.x*B.x+A.y*B.y+A.z*B.z;}Point operator *(double B,Point A) {return Point(A.x*B,A.y*B,A.z*B);}Point operator +(Point A,Point B) {return Point(A.x+B.x,A.y+B.y,A.z+B.z);}Point operator -(Point A,Point B) {return Point(A.x-B.x,A.y-B.y,A.z-B.z);}inline int next() {    int w = 0;    double a,b,cc,delta,gen;    tt = oo;    for(int i=1;i<=n;i++) {        a = dir*dir;        b = 2.0*(s-c[i])*dir;        cc = P(s-c[i]) - P(r[i]);        if ((delta = P(b)-4*a*cc)>-eps) {           if (fabs(delta)
     
      eps && gen
      
       eps && gen
       
        

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.