cgv
Loading...
Searching...
No Matches
ray.h
1#pragma once
2
3#include "vec.h"
4#include "inv.h"
5
6namespace cgv {
7namespace math {
8
10template<class T>
11struct ray {
12 vec<T> origin;
13 vec<T> direction;
14
16 ray(unsigned int n = 3) {
17 origin.resize(n);
18 origin.fill(T(0));
19 direction.resize(n);
20 direction.fill(T(0));
21 }
22
24 ray(const vec<T>& origin, const vec<T>& direction) : origin(origin), direction(direction) {
25 assert(origin.dim() == directin.dim());
26 }
27
29 vec<T> position(T t) const {
30 return origin + t * direction;
31 }
32};
33
35typedef ray<float> rayn;
37typedef ray<double> drayn;
38
39} // namespace math
40} // namespace cgv
A column vector class.
Definition vec.h:28
void fill(const T &v)
fill elements of vector with scalar v
Definition vec.h:463
void resize(unsigned dim)
resize the vector
Definition vec.h:496
unsigned dim() const
number of elements
Definition vec.h:61
the cgv namespace
Definition print.h:11
Struct template for varying n-dimensional rays with arbitrary data type defined by origin and directi...
Definition ray.h:11
ray(const vec< T > &origin, const vec< T > &direction)
Construct a ray with given origin and direction. The given orign and direction must have the same dim...
Definition ray.h:24
vec< T > position(T t) const
Return the position of the ray at the given distance (ray parameter t) from its origin.
Definition ray.h:29
ray(unsigned int n=3)
Construct an invalid ray with origin at zero and undefined direction.
Definition ray.h:16