Bo from the great god of Jiuye
# Include <cstdio> # include <cstdlib> # include <cstring> # include <algorithm> # include <cmath> using namespace STD; const double EPS = 1e-9; const int maxn = 40; struct point3 // space point {Double X, Y, Z; point3 (double x = 0, Double Y = 0, Double Z = 0 ): x (x), y (Y), Z (z) {} point3 (const point3 & A) {x =. x; y =. y; Z =. z; return;} void showp () {printf ("% F \ n", x, y, z);} point3 operator + (point3 & RHS) {Return point3 (x + RHS. x, Y + RHS. y, Z + RHS. z) ;}}; struct line3 // Spatial Straight Line {point3 A, B ;}; struct plane3 // spatial plane {point3 A, B, C; plane3 () {} plane3 (point3 A, point3 B, point3 C): A (a), B (B), C (c) {} void showplane () {. showp (); B. showp (); C. showp (); Return ;}}; double DCMP (double A) {If (FABS (a) <EPS) return 0; return a <0? -1: 1;} // 3D Cross Product point3 cross3 (point3 U, point3 v) {point3 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;} // three-dimensional dot product double dot3 (point3 U, point3 v) {return U. x * v. X + U. y * v. Y + U. z * v. z;} // vector difference point3 subt (point3 U, point3 v) {point3 ret; ret. X = u. x-v. x; ret. y = u. y-v. y; ret. z = u. z-v. z; return ret;} // distance between two points: Double twopointdistance (point3 P1, point3 P2) {return SQRT (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y) + (p1.z-p2.z) * (p1.z-p2.z);} // vector modulo double vectorlenth (point3 p) {return SQRT (P. x * P. X + P. y * P. Y + P. z * P. z);} // distance from the space to the double linetoline (line3 U, line3 V, point3 & TMP) {TMP = cross3 (subt (U. a, U. b), subt (v. a, V. b); Return FABS (dot3 (subt (U. a, V. a), TMP)/vectorlenth (TMP);} // obtain the plane method vector point3 PVEC (plane3 s) {return cross3 (subt (S. a, S. b), subt (S. b, S. c);} // point of intersection between the spatial plane and the straight line point3 intersection (line3 L, plane3 s) {point3 ret = PVEC (s); Double T = (Ret. x * (S. a. x-l.a.x) + ret. y * (S. a. y-l.a.y) + ret. z * (S. a. z-l.a.z)/(Ret. x * (L. b. x-l.a.x) + ret. y * (L. b. y-l.a.y) + ret. z * (L. b. z-l.a.z); ret. X = L. a. X + (L. b. x-L. a. x) * t; ret. y = L. a. Y + (L. b. y-L. a. y) * t; ret. z = L. a. Z + (L. b. z-L. a. z) * t; return ret ;} /************************/* Bo from the 9 wild god */
Computation geometric template