33#include <initializer_list>
50 std::enable_if_t<std::is_floating_point_v<Value_type>,
bool> =
true>
67 constexpr static const size_t components = 3;
70 constexpr static const size_t byte_size = components *
sizeof(
value_type);
83 : x(x_), y(y_), z(z_) {}
86 : x(o2.x), y(o2.y), z(z_) {}
89 : x(v[0]), y(v[1]), z(v[2]) {}
91 constexpr Vector3F(std::initializer_list<value_type> v) noexcept
92 : x(v[0]), y(v[1]), z(v[2]) {}
114 explicit operator pointer() noexcept {
return &x; }
151 { x=vx; y=vy; z=vz;
return *
this; }
155 { x=xyz[0]; y=xyz[1]; z=xyz[2];
return *
this; }
159 { x+=dx; y+=dy; z+=dz;
return *
this; }
163 { x*=sx; y*=sy; z*=sz;
return *
this; }
167 { x*=s; y*=s; z*=s;
return *
this; }
171 x+=rhs.
x; y+=rhs.y; z+=rhs.z;
177 x-=rhs.
x; y-=rhs.y; z-=rhs.z;
203 return rotateZ(std::sin(radians), std::cos(radians));
209 x = x0 * cos - y * sin;
210 y = x0 * sin + y * cos;
224 return x*x + y*y + z*z;
231 return std::sqrt(length_sq());
263 return dx*dx + dy*dy + dz*dz;
270 return std::sqrt(dist_sq(o));
278 return x*o.
x + y*o.
y + z*o.
z;
296 x = a.
y * b.z - a.z * b.y;
297 y = a.z * b.x - a.x * b.z;
298 z = a.x * b.y - a.y * b.x;
308 return dot(o) / ( length() * o.
length() ) ;
317 return std::acos( cos_angle(o) );
321 const value_type eps = std::numeric_limits<value_type>::epsilon();
330 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
342 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
348 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
354 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
360 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
366 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
368 return out << v.toString();
372 static_assert(
alignof(float) ==
alignof(
Vec3f));
373 static_assert(
sizeof(float)*3 ==
sizeof(
Vec3f));
379 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
383 static_assert(
alignof(float) ==
alignof(
Point3f));
384 static_assert(
sizeof(float)*3 ==
sizeof(
Point3f));
398 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
406 std::string
toString() const noexcept {
return "Ray[orig "+orig.
toString()+
", dir "+dir.toString() +
"]"; }
410 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
412 return out << v.toString();
416 static_assert(
alignof(float) ==
alignof(
Ray3f));
417 static_assert(
sizeof(float)*6 ==
sizeof(
Ray3f));
2D vector using two value_type components.
3D vector using three value_type components.
constexpr Vector3F(const value_type v) noexcept
constexpr reference operator[](size_t i) noexcept
Returns writeable reference to component
constexpr Vector3F & cross(const Vector3F &a, const Vector3F &b) noexcept
cross product this = a x b, with a, b different from this
constexpr Vector3F() noexcept
constexpr_cxx26 Vector3F & rotateZ(const value_type radians) noexcept
Rotates this vector around the Z-axis in place, returns *this.
constexpr Vector3F & set(const Vec2f &o, const value_type z_) noexcept
TODO constexpr bool operator<=>(const vec3f_t& rhs ) const noexcept { return ... }.
const value_type & const_reference
constexpr bool operator==(const Vector3F &rhs) const noexcept
constexpr Vector3F & operator/=(const value_type s) noexcept
Divide this vector with given scale factor.
constexpr_cxx26 value_type angle(const Vector3F &o) const noexcept
Return the angle between to vectors in radians.
constexpr Vector3F & operator=(const Vector3F &) noexcept=default
constexpr value_type cos_angle(const Vector3F &o) const noexcept
Return the cosines of the angle between to vectors.
constexpr Vector3F & normalize() noexcept
Normalize this vector in place.
const value_type * const_pointer
constexpr Vector3F & operator=(Vector3F &&) noexcept=default
Vector2F< value_type, std::is_floating_point_v< Value_type > > Vec2
constexpr Vector3F(const_iterator v) noexcept
constexpr Vector3F & operator-=(const Vector3F &rhs) noexcept
this = this - rhs, returns this.
constexpr_cxx23 bool intersects(const Vector3F &o) const noexcept
constexpr iterator get(iterator xyz) const noexcept
xyz = this, returns xyz.
constexpr Vector3F & set(const value_type vx, const value_type vy, const value_type vz) noexcept
constexpr value_type length() const noexcept
Return the length of a vector, a.k.a the norm or magnitude
constexpr Vector3F & scale(const value_type s) noexcept
this = this * s, returns this.
constexpr value_type dist(const Vector3F &o) const noexcept
Return the distance between this vector and the given one.
constexpr Vector3F & mul(const value_type sx, const value_type sy, const value_type sz) noexcept
this = this * {sx, sy, sz}, returns this.
constexpr Vector3F & rotateZ(const value_type sin, const value_type cos) noexcept
Rotates this vector in place, returns *this.
constexpr Vector3F & operator+=(const Vector3F &rhs) noexcept
this = this + rhs, returns this.
constexpr value_type dist_sq(const Vector3F &o) const noexcept
Return the squared distance between this vector and the given one.
constexpr Vector3F(std::initializer_list< value_type > v) noexcept
constexpr Vector3F(const Vec2 &o2, const value_type z_) noexcept
constexpr Vector3F & add(const value_type dx, const value_type dy, const value_type dz) noexcept
this = this + {dx, dy, dz}, returns this.
constexpr const_iterator cbegin() const noexcept
constexpr bool is_zero() const noexcept
constexpr value_type dot(const Vector3F &o) const noexcept
Return the dot product of this vector and the given one.
constexpr value_type length_sq() const noexcept
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
constexpr Vector3F(const Vector3F &o) noexcept=default
constexpr Vector3F cross(const Vector3F &b) const noexcept
cross product this x b
constexpr Vector3F & set(const_iterator xyz) noexcept
this = xyz, returns this.
const value_type * const_iterator
constexpr Vector3F(const value_type x_, const value_type y_, const value_type z_) noexcept
constexpr Vector3F & operator*=(const value_type s) noexcept
Scale this vector with given scale factor.
constexpr Vector3F(Vector3F &&o) noexcept=default
constexpr iterator begin() noexcept
std::string toString() const noexcept
constexpr bool equals(const Vector3F &o, const value_type epsilon=std::numeric_limits< value_type >::epsilon()) const noexcept
std::string to_string(const alphabet &v) noexcept
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr is_zero(const T &a, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
Returns true if the given value is less than epsilon, w/ epsilon > 0.
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr equals(const T &a, const T &b, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
Returns true if both values are equal, i.e.
constexpr T abs(const T x) noexcept
Returns the absolute value of an arithmetic number (w/ branching) in O(1)
constexpr Quaternion< T > operator-(const Quaternion< T > &lhs, const Quaternion< T > &rhs) noexcept
constexpr Vector2F< T > operator/(const Vector2F< T > &lhs, const T s) noexcept
constexpr Matrix4< T > operator*(const Matrix4< T > &lhs, const Matrix4< T > &rhs) noexcept
constexpr Quaternion< T > operator+(const Quaternion< T > &lhs, const Quaternion< T > &rhs) noexcept
std::ostream & operator<<(std::ostream &out, const Matrix4< T > &v) noexcept
constexpr const jau::fraction_i64 zero(0l, 1lu)
zero is 0/1
constexpr const jau::fraction_i64 one(1l, 1lu)
one is 10^0 or 1/1
Simple compound denoting a ray.
Point3F< T > orig
Origin of Ray.
std::string toString() const noexcept
Vector3F< T > dir
Normalized direction vector of ray.