Commit e24ed5a69ce1588080158f2072b84ef33dec349d

Authored by Pavel Govyadinov
1 parent 8495a970

circle added

Showing 1 changed file with 131 additions and 0 deletions   Show diff stats
stim/math/circle.h 0 → 100644
  1 +#ifndef STIM_CIRCLE_H
  2 +#define STIM_CIRCLE_H
  3 +
  4 +//enable CUDA_CALLABLE macro
  5 +#include <stim/cuda/cudatools/callable.h>
  6 +#include <stim/math/vector.h>
  7 +#include <stim/math/triangle.h>
  8 +#include <stim/math/quaternion.h>
  9 +#include <stim/math/rect.h>
  10 +#include <iostream>
  11 +#include <iomanip>
  12 +#include <algorithm>
  13 +
  14 +namespace stim
  15 +{
  16 +
  17 +template <class T>
  18 +struct circle : rect<T>
  19 +{
  20 + private:
  21 + T theta;
  22 +
  23 + public:
  24 +
  25 + using stim::rect<T>::p;
  26 + using stim::rect<T>::normal;
  27 + using stim::rect<T>::center;
  28 + using stim::rect<T>::scale;
  29 + ///base constructor
  30 + ///@param th value of the angle of the starting point from 0 to 360.
  31 + CUDA_CALLABLE circle(float th = 0.0) : rect<T>()
  32 + {
  33 + theta = th;
  34 + }
  35 +
  36 + ///create a rectangle given a size and position in Z space.
  37 + ///@param size: size of the rectangle in ND space.
  38 + ///@param z_pos z coordinate of the rectangle.
  39 + ///@param th value of the angle of the starting point from 0 to 360.
  40 + CUDA_CALLABLE circle(T size, T zpos = (T)0, float th = 0.0) : rect<T>(size, zpos)
  41 + {
  42 + theta = th;
  43 + }
  44 +
  45 + ///create a rectangle from a center point, normal
  46 + ///@param c: x,y,z location of the center.
  47 + ///@param n: x,y,z direction of the normal.
  48 + ///@param th value of the angle of the starting point from 0 to 360.
  49 + CUDA_CALLABLE circle(vec<T> c, vec<T> n = vec<T>(0,0,1), float th = 0.0) : rect<T>(c, n)
  50 + {
  51 + theta = th;
  52 + }
  53 +
  54 + ///create a rectangle from a center point, normal, and size
  55 + ///@param c: x,y,z location of the center.
  56 + ///@param s: size of the rectangle.
  57 + ///@param n: x,y,z direction of the normal.
  58 + ///@param th value of the angle of the starting point from 0 to 360.
  59 + 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)
  60 + {
  61 + theta = th;
  62 + }
  63 +
  64 + ///creates a rectangle from a centerpoint and an X and Y direction vectors.
  65 + ///@param center: x,y,z location of the center.
  66 + ///@param directionX: u,v,w direction of the X vector.
  67 + ///@param directionY: u,v,w direction of the Y vector.
  68 + ///@param th value of the angle of the starting point from 0 to 360.
  69 + CUDA_CALLABLE circle(vec<T> center, vec<T> directionX, vec<T> directionY, float th = 0.0) : rect<T>(center, directionX, directionY)
  70 + {
  71 + theta = th;
  72 + }
  73 +
  74 + ///creates a rectangle from a size, centerpoint, X, and Y direction vectors.
  75 + ///@param size of the rectangle in ND space.
  76 + ///@param center: x,y,z location of the center.
  77 + ///@param directionX: u,v,w direction of the X vector.
  78 + ///@param directionY: u,v,w direction of the Y vector.
  79 + ///@param th value of the angle of the starting point from 0 to 360.
  80 + CUDA_CALLABLE circle(T size, vec<T> center, vec<T> directionX, vec<T> directionY, float th = 0.0) : rect<T>(size, center, directionX, directionY)
  81 + {
  82 + theta = th;
  83 + }
  84 +
  85 + ///creates a rectangle from a size, centerpoint, X, and Y direction vectors.
  86 + ///@param size of the rectangle in ND space, size[0] = size in X, size[1] = size in Y.
  87 + ///@param center: x,y,z location of the center.
  88 + ///@param directionX: u,v,w direction of the X vector.
  89 + ///@param directionY: u,v,w direction of the Y vector.
  90 + ///@param th value of the angle of the starting point from 0 to 360.
  91 + 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)
  92 + {
  93 + theta = th;
  94 + }
  95 +
  96 + ///returns a vector with the points on the initialized circle.
  97 + ///connecting the points results in a circle.
  98 + ///@param n: integer for the number of points representing the circle.
  99 + std::vector<stim::vec<T> >
  100 + getPoints(int n)
  101 + {
  102 + std::vector<stim::vec<T> > result;
  103 + stim::vec<T> point;
  104 + T x,y;
  105 + float step = 360.0/(float) n;
  106 + for(float j = theta; j <= theta+360.0; j += step)
  107 + {
  108 + y = 0.5*cos(j*2.0*M_PI/360.0)+0.5;
  109 + x = 0.5*sin(j*2.0*M_PI/360.0)+0.5;
  110 + result.push_back(p(x,y));
  111 + }
  112 +
  113 + return result;
  114 + }
  115 +
  116 + ///returns a vector with the points on the initialized circle.
  117 + ///connecting the points results in a circle.
  118 + ///@param n: integer for the number of points representing the circle.
  119 + stim::vec<T>
  120 + p(T theta)
  121 + {
  122 + T x,y;
  123 + y = 0.5*cos(theta*2.0*M_PI/360.0)+0.5;
  124 + x = 0.5*sin(theta*2.0*M_PI/360.0)+0.5;
  125 + return p(x,y);
  126 + }
  127 +};
  128 +
  129 +}
  130 +
  131 +#endif
... ...