#ifndef STIM_CIRCLE_H #define STIM_CIRCLE_H #include #include #include #include #include #include #include namespace stim{ template class circle : plane { private: stim::vec3 Y; CUDA_CALLABLE void init() { Y = U.cross(N).norm(); } public: using stim::plane::n; using stim::plane::P; using stim::plane::N; using stim::plane::U; using stim::plane::rotate; using stim::plane::setU; ///base constructor ///@param th value of the angle of the starting point from 0 to 360. CUDA_CALLABLE circle() : plane() { init(); } ///create a rectangle given a size and position in Z space. ///@param size: size of the rectangle in ND space. ///@param z_pos z coordinate of the rectangle. CUDA_CALLABLE circle(T size, T z_pos = (T)0) : plane() { init(); center(stim::vec3(0,0,z_pos)); scale(size); } ///create a rectangle from a center point, normal ///@param c: x,y,z location of the center. ///@param n: x,y,z direction of the normal. CUDA_CALLABLE circle(vec3 c, vec3 n = vec3(0,0,1)) : plane() { center(c); normal(n); init(); } ///create a rectangle from a center point, normal, and size ///@param c: x,y,z location of the center. ///@param s: size of the rectangle. ///@param n: x,y,z direction of the normal. CUDA_CALLABLE circle(vec3 c, T s, vec3 n = vec3(0,0,1)) : plane() { init(); center(c); rotate(n, U, Y); scale(s); } ///create a rectangle from a center point, normal, and size ///@param c: x,y,z location of the center. ///@param s: size of the rectangle. ///@param n: x,y,z direction of the normal. ///@param u: x,y,z direction for the zero vector (from where the rotation starts) CUDA_CALLABLE circle(vec3 c, T s, vec3 n = vec3(0,0,1), vec3 u = vec3(1, 0, 0)) : plane() { init(); setU(u); center(c); normal(n); scale(s); } ///scales the circle by a certain factor ///@param factor: the factor by which the dimensions of the shape are scaled. CUDA_CALLABLE void scale(T factor) { U *= factor; Y *= factor; } ///sets the normal for the cirlce ///@param n: x,y,z direction of the normal. CUDA_CALLABLE void normal(vec3 n) { rotate(n, Y); } ///sets the center of the circle. ///@param n: x,y,z location of the center. CUDA_CALLABLE void center(vec3 p){ this->P = p; } ///boolean comparison bool operator==(const circle & rhs) { if(P == rhs.P && U == rhs.U && Y == rhs.Y) return true; else return false; } ///get the world space value given the planar coordinates a, b in [0, 1] CUDA_CALLABLE stim::vec3 p(T a, T b) { stim::vec3 result; vec3 A = this->P - this->U * (T)0.5 - Y * (T)0.5; result = A + this->U * a + Y * b; return result; } ///parenthesis operator returns the world space given rectangular coordinates a and b in [0 1] CUDA_CALLABLE stim::vec3 operator()(T a, T b) { return p(a,b); } ///returns a vector with the points on the initialized circle. ///connecting the points results in a circle. ///@param n: integer for the number of points representing the circle. std::vector > getPoints(int n) { std::vector > result; stim::vec3 point; T x,y; float step = 360.0/(float) n; for(float j = 0; j <= 360.0; j += step) { y = 0.5*cos(j*2.0*M_PI/360.0)+0.5; x = 0.5*sin(j*2.0*M_PI/360.0)+0.5; result.push_back(p(x,y)); } return result; } ///returns a vector with the points on the initialized circle. ///connecting the points results in a circle. ///@param n: integer for the number of points representing the circle. stim::vec3 p(T theta) { T x,y; y = 0.5*cos(theta*2.0*M_PI/360.0)+0.5; x = 0.5*sin(theta*2.0*M_PI/360.0)+0.5; return p(x,y); } }; } #endif