Go to the documentation of this file.
6 #ifndef OPENMPCD_VECTOR3D_HPP
7 #define OPENMPCD_VECTOR3D_HPP
18 #ifdef OPENMPCD_PLATFORM_CUDA
23 #include <boost/math/constants/constants.hpp>
24 #include <boost/random/uniform_01.hpp>
25 #include <boost/static_assert.hpp>
26 #include <boost/type_traits/is_floating_point.hpp>
151 void set(
const T x_,
const T y_,
const T z_)
166 const T cx=y*rhs.z-z*rhs.y;
167 const T cy=z*rhs.x-x*rhs.z;
168 const T cz=x*rhs.y-y*rhs.x;
252 #ifndef __CUDA_ARCH__
278 return normalized.
dot(*
this) * normalized;
297 BOOST_STATIC_ASSERT(boost::is_floating_point<T>::value);
310 const T thisDotAxis =
dot(axis);
312 const Vector3D projectionOntoAxis = axis*thisDotAxis;
313 *
this = projectionOntoAxis +
cos(angle) * (*
this - projectionOntoAxis) +
sin(angle) * axisCrossThis;
334 return x<0 || y<0 || z<0;
343 #ifndef __CUDA_ARCH__
369 boost::random::uniform_01<T> dist0i1e;
373 const T X_1 = dist0i1e(rng);
374 const T X_2 = dist0i1e(rng);
379 #ifdef OPENMPCD_PLATFORM_CUDA
389 dist0e1i(rng, &X_1, &X_2);
412 const T z = 2 * X_1 - 1;
413 const T phiOverPi = 2 * X_2;
435 if(x == rhs.x && y == rhs.y && z == rhs.z)
560 #ifndef __CUDA_ARCH__
616 stream<<vector.x<<
" "<<vector.y<<
" "<<vector.z;
bool operator<(const Vector3D &rhs) const
Less-than operator.
OPENMPCD_CUDA_HOST_AND_DEVICE bool isFinite() const
Returns whether all components are finite, i.e.
bool hasNegativeComponent() const
Returns whether at least one of the components of this vector is negative.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D getRotatedAroundNormalizedAxis(const Vector3D &axis, const T angle) const
Returns this vector, but rotated about the given axis by the given angle.
OPENMPCD_CUDA_HOST_AND_DEVICE RealType magnitudeSquared() const
Returns the square of the magnitude of this vector.
OPENMPCD_CUDA_HOST_AND_DEVICE boost::enable_if< boost::is_floating_point< T >, bool >::type isZero(const T &val)
Returns whether the given value is zero.
OPENMPCD_CUDA_HOST_AND_DEVICE T getZ() const
Returns the z coordinate.
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
OPENMPCD_CUDA_HOST_AND_DEVICE T cos(const T x)
Returns the cosine of the argument.
OPENMPCD_CUDA_HOST_AND_DEVICE bool operator==(const Vector3D &rhs) const
Equality operator.
const OPENMPCD_CUDA_HOST_AND_DEVICE T dot(const Vector3D &rhs) const
Returns the scalar product of this vector with the given vector.
Contains information on certain types.
OPENMPCD_CUDA_HOST_AND_DEVICE T getX() const
Returns the x coordinate.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D operator-(const Vector3D &rhs) const
Subtraction operator.
OPENMPCD_CUDA_HOST_AND_DEVICE void normalize()
Normalizes this vector.
OPENMPCD_CUDA_HOST_AND_DEVICE void rotateAroundNormalizedAxis(const Vector3D &axis, const T angle)
Rotates this vector about the given axis by the given angle.
const Vector3D< std::complex< T > > getComplexVector() const
Returns the complex version of this vector.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D & operator*=(const T scale)
Scalar multiplication and assignment operator.
#define OPENMPCD_CUDA_DEVICE
Denotes a function to be callable from a CUDA Device.
#define OPENMPCD_CUDA_HOST_AND_DEVICE
Denotes a function to be callable both from the Host and from a CUDA Device.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D operator+(const Vector3D &rhs) const
Addition operator.
friend std::ostream & operator<<(std::ostream &stream, const Vector3D &vector)
Output operator for streams.
OPENMPCD_CUDA_HOST_AND_DEVICE T getY() const
Returns the y coordinate.
OPENMPCD_CUDA_HOST_AND_DEVICE void addToX(const T val)
Adds the given value to the x coordinate.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D & operator+=(const Vector3D &rhs)
Addition-and-assignment operator.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D operator/(const T divisor) const
Scalar division operator.
static const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D getUnitVectorFromRandom01(const T X_1, const T X_2)
Constructs a unit vector from the two given random variables.
T getAngle(const Vector3D &rhs) const
Returns the the angle between this vector and the given one.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D getNormalized() const
Returns this vector, but normalized.
boost::mt11213b RNG
The random number generator type.
OPENMPCD_CUDA_HOST_AND_DEVICE const friend Vector3D operator*(const T scale, const Vector3D &vec)
Scalar multiplication operator.
OPENMPCD_CUDA_HOST_AND_DEVICE void addToZ(const T val)
Adds the given value to the z coordinate.
static const OPENMPCD_CUDA_HOST_AND_DEVICE T dot(const Vector3D< T > &lhs, const Vector3D< T > &rhs)
Returns the scalar product two vectors.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D operator-() const
The negation operator.
const Vector3D getProjectedOnto(const Vector3D &onto) const
Returns the projection of this vector onto the given one.
OPENMPCD_CUDA_HOST_AND_DEVICE RealType magnitude() const
Returns the magnitude of this vector.
#define OPENMPCD_CUDA_HOST
Denotes a function to be callable from the Host.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D cross(const Vector3D &rhs) const
Returns the cross product of this vector with the given vector.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D operator*(const T scale) const
Scalar multiplication operator.
static const OPENMPCD_CUDA_HOST Vector3D getRandomUnitVector(RNG &rng)
Returns a random vector with unit length; all directions are equally likely.
T getCosineOfAngle(const Vector3D &rhs) const
Returns the cosine of the angle between this vector and the given one.
OPENMPCD_CUDA_HOST_AND_DEVICE void sincospi(const T x, T *const s, T *const c)
Computes both the sine and the cosine of the product of the argument and .
OPENMPCD_CUDA_HOST_AND_DEVICE void setX(const T val)
Sets the x coordinate.
OPENMPCD_CUDA_HOST_AND_DEVICE void set(const T x_, const T y_, const T z_)
Sets the coordinates.
OPENMPCD_CUDA_HOST_AND_DEVICE void addToY(const T val)
Adds the given value to the y coordinate.
OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D(const T x_, const T y_, const T z_)
Constructs a vector from its coordinates.
OPENMPCD_CUDA_HOST_AND_DEVICE void setY(const T val)
Sets the y coordinate.
OPENMPCD_CUDA_HOST_AND_DEVICE T sqrt(const T x)
Returns the sqaure root of the argument.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D & operator/=(const T divisor)
Scalar division and assignment operator.
Defines common mathematical functions.
const Vector3D getPerpendicularTo(const Vector3D &rhs) const
Returns the part of this vector that is perpendicular to the given vector.
OPENMPCD_CUDA_HOST_AND_DEVICE bool operator!=(const Vector3D &rhs) const
Inequality operator.
OPENMPCD_CUDA_HOST_AND_DEVICE boost::enable_if< boost::is_floating_point< T >, T >::type getRealPart(const T &val)
Returns the real part of the given value.
TypeTraits< T >::RealType RealType
The real-value type matching T.
Philox4x32-10 counter-bases PRNG.
OPENMPCD_CUDA_HOST_AND_DEVICE T acos(const T x)
Returns the arc cosine of the argument.
OPENMPCD_CUDA_HOST_AND_DEVICE RealType getMagnitude() const
Returns the magnitude of this vector.
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D & operator-=(const Vector3D &rhs)
Subtraction-and-assignment operator.
OPENMPCD_CUDA_HOST_AND_DEVICE T sin(const T x)
Returns the sine of the argument.
OPENMPCD_CUDA_HOST_AND_DEVICE void setZ(const T val)
Sets the z coordinate.
OPENMPCD_CUDA_HOST_AND_DEVICE RealType getMagnitudeSquared() const
Returns the square of the magnitude of this vector.