From 09b24449af2408093318ce4c0fcc419d78f040d7 Mon Sep 17 00:00:00 2001 From: pgovyadi Date: Mon, 25 Jan 2016 15:01:20 -0600 Subject: [PATCH] changes to plane and additing of the old rts plane class --- stim/math/plane_old.h | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+), 0 deletions(-) create mode 100644 stim/math/plane_old.h diff --git a/stim/math/plane_old.h b/stim/math/plane_old.h new file mode 100644 index 0000000..b009cad --- /dev/null +++ b/stim/math/plane_old.h @@ -0,0 +1,179 @@ +#ifndef RTS_PLANE_H +#define RTS_PLANE_H + +#include +#include +#include "rts/cuda/callable.h" + + +namespace stim{ +template class plane; +} + +template +CUDA_CALLABLE stim::plane operator-(stim::plane v); + +namespace stim{ + +template +class plane{ + + //a plane is defined by a point and a normal + +private: + + vec P; //point on the plane + vec N; //plane normal + + CUDA_CALLABLE void init(){ + P = vec(0, 0, 0); + N = vec(0, 0, 1); + } + + +public: + + //default constructor + CUDA_CALLABLE plane(){ + init(); + } + + CUDA_CALLABLE plane(vec n, vec p = vec(0, 0, 0)){ + P = p; + N = n.norm(); + } + + CUDA_CALLABLE plane(T z_pos){ + init(); + P[2] = z_pos; + } + + //create a plane from three points (a triangle) + CUDA_CALLABLE plane(vec a, vec b, vec c){ + P = c; + N = (c - a).cross(b - a); + if(N.len() == 0) //handle the degenerate case when two vectors are the same, N = 0 + N = 0; + else + N = N.norm(); + } + + template< typename U > + CUDA_CALLABLE operator plane(){ + + plane result(N, P); + return result; + } + + CUDA_CALLABLE vec norm(){ + return N; + } + + CUDA_CALLABLE vec p(){ + return P; + } + + //flip the plane front-to-back + CUDA_CALLABLE plane flip(){ + plane result = *this; + result.N = -result.N; + return result; + } + + //determines how a vector v intersects the plane (1 = intersects front, 0 = within plane, -1 = intersects back) + CUDA_CALLABLE int face(vec v){ + + T dprod = v.dot(N); //get the dot product between v and N + + //conditional returns the appropriate value + if(dprod < 0) + return 1; + else if(dprod > 0) + return -1; + else + return 0; + } + + //determine on which side of the plane a point lies (1 = front, 0 = on the plane, -1 = back) + CUDA_CALLABLE int side(vec p){ + + vec v = p - P; //get the vector from P to the query point p + + return face(v); + } + + //compute the component of v that is perpendicular to the plane + CUDA_CALLABLE vec perpendicular(vec v){ + return N * v.dot(N); + } + + //compute the projection of v in the plane + CUDA_CALLABLE vec parallel(vec v){ + return v - perpendicular(v); + } + + CUDA_CALLABLE void decompose(vec v, vec& para, vec& perp){ + perp = N * v.dot(N); + para = v - perp; + } + + //get both the parallel and perpendicular components of a vector v w.r.t. the plane + CUDA_CALLABLE void project(vec v, vec &v_par, vec &v_perp){ + + v_perp = v.dot(N); + v_par = v - v_perp; + } + + //compute the reflection of v off of the plane + CUDA_CALLABLE vec reflect(vec v){ + + //compute the reflection using N_prime as the plane normal + vec par = parallel(v); + vec r = (-v) + par * 2; + + /*std::cout<<"----------------REFLECT-----------------------------"< operator-() + { + rts::plane p = *this; + + //negate the normal vector + p.N = -p.N; + + return p; + } + + //output a string + std::string str(){ + std::stringstream ss; + ss<<"P: "< operator- <> (rts::plane v); + + + +}; + +} + +//arithmetic operators + +//negative operator flips the plane (front to back) +//template + + + + +#endif -- libgit2 0.21.4