circle.h 4.11 KB
#ifndef STIM_CIRCLE_H
#define STIM_CIRCLE_H

//enable CUDA_CALLABLE macro
#include <stim/cuda/cudatools/callable.h>
#include <stim/math/vector.h>
#include <stim/math/triangle.h>
#include <stim/math/quaternion.h>
#include <stim/math/rect.h>
#include <iostream>
#include <iomanip>
#include <algorithm>

namespace stim
{

template <class T>
struct circle : rect<T>
{
	private:
		T theta;

	public:

		using stim::rect<T>::p;
		using stim::rect<T>::normal;
		using stim::rect<T>::center;
		using stim::rect<T>::scale;
		///base constructor
		///@param th value of the angle of the starting point from 0 to 360.
		CUDA_CALLABLE circle(float th = 0.0) : rect<T>()
		{
			theta = th;
		}

		///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.
		///@param th value of the angle of the starting point from 0 to 360.
		CUDA_CALLABLE circle(T size, T zpos = (T)0, float th = 0.0) : rect<T>(size, zpos)
		{
			theta = th;
		}

		///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.
		///@param th value of the angle of the starting point from 0 to 360.
		CUDA_CALLABLE circle(vec<T> c, vec<T> n = vec<T>(0,0,1), float th = 0.0) : rect<T>(c, n)
		{
			theta = th;
		}
		
		///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 th value of the angle of the starting point from 0 to 360.
		CUDA_CALLABLE circle(vec<T> c, T s, vec<T> n = vec<T>(0,0,1), float th = 0.0):rect<T>(c,s,n)
		{
			theta = th;
		}

		///creates a rectangle from a centerpoint and an X and Y direction vectors.
		///@param center: x,y,z location of the center.
		///@param directionX: u,v,w direction of the X vector.
		///@param directionY: u,v,w direction of the Y vector.
		///@param th value of the angle of the starting point from 0 to 360.
		CUDA_CALLABLE circle(vec<T> center, vec<T> directionX, vec<T> directionY, float th = 0.0) : rect<T>(center, directionX, directionY)
		{
			theta = th;
		}

		///creates a rectangle from a size, centerpoint, X, and Y direction vectors.
		///@param size of the rectangle in ND space.
		///@param center: x,y,z location of the center.
		///@param directionX: u,v,w direction of the X vector.
		///@param directionY: u,v,w direction of the Y vector.
		///@param th value of the angle of the starting point from 0 to 360.
		CUDA_CALLABLE circle(T size, vec<T> center, vec<T> directionX, vec<T> directionY,  float th = 0.0) : rect<T>(size, center, directionX, directionY)
		{
			theta = th;
		}
		
		///creates a rectangle from a size, centerpoint, X, and Y direction vectors.
		///@param size of the rectangle in ND space, size[0] = size in X, size[1] = size in Y.
		///@param center: x,y,z location of the center.
		///@param directionX: u,v,w direction of the X vector.
		///@param directionY: u,v,w direction of the Y vector.
		///@param th value of the angle of the starting point from 0 to 360.
		CUDA_CALLABLE circle(vec<T> size, vec<T> center, vec<T> directionX, vec<T> directionY, float th = 0.0) : rect<T>(size, center, directionX, directionY)
		{
			theta = th;
		}

		///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<stim::vec<T> >
		getPoints(int n)
		{
			std::vector<stim::vec<T> > result;
			stim::vec<T> point;
			T x,y;
			float step = 360.0/(float) n;
			for(float j = theta; j <= theta+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::vec<T>
		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