程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> SGU110 計算幾何 Computational Geometry

SGU110 計算幾何 Computational Geometry

編輯:C++入門知識

題意:三維空間N個球體,給一個光束的方向,求它在這些球體間的反射情況(球面反射)。

Problem: N spheres are in a 3D-space. Give you a direction 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).

題解:如下圖所示,每次反射分為兩步。第一步利用圖中關系求出tt,進而求出反射點。第二步利用投影定理求出反射光線的方向向量。

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 && geneps && gen

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved