Implement Normalized, LinearCombination, and operator<< on Vector4s
This commit is contained in:
parent
9645a09a6c
commit
c49457a817
2 changed files with 47 additions and 1 deletions
|
@ -224,6 +224,42 @@ operator*(const Double& lhs,
|
|||
return rhs * lhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Normalized --
|
||||
*/
|
||||
Vector4
|
||||
Normalized(const Vector4& v)
|
||||
{
|
||||
return Vector4(v).Normalize();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::LinearCombination --
|
||||
*/
|
||||
Vector4
|
||||
LinearCombination(const Double k1, const Vector4& v1,
|
||||
const Double k2, const Vector4& v2,
|
||||
const Double k3, const Vector4& v3)
|
||||
{
|
||||
return Vector4(k1 * v1.X() + k2 * v2.X() + k3 * v3.X(),
|
||||
k1 * v1.Y() + k2 * v2.Y() + k3 * v3.Y(),
|
||||
k1 * v1.Z() + k2 * v2.Z() + k3 * v3.Z());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::operator<< --
|
||||
*/
|
||||
std::ostream &
|
||||
operator<<(std::ostream &os, const Vector3 &v)
|
||||
{
|
||||
// Stream the vector like this: <x, y, z>
|
||||
os << "<" << v.X() << ", " << v.Y() << ", " << v.Z() << ">";
|
||||
return os;
|
||||
}
|
||||
|
||||
} /* namespace basics */
|
||||
} /* namespace charles */
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#ifndef __BASICS_VECTOR_HH__
|
||||
#define __BASICS_VECTOR_HH__
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include "basics/matrix.hh"
|
||||
#include "basics/types.hh"
|
||||
|
||||
|
@ -63,7 +65,15 @@ Vector4 operator*(const Double& lhs, const Vector4& rhs);
|
|||
|
||||
|
||||
/** Normalize the given vector and return a copy of it. */
|
||||
Vector4& Normalized(const Vector4& v);
|
||||
Vector4 Normalized(const Vector4& v);
|
||||
|
||||
|
||||
Vector4 LinearCombination(const Double k1, const Vector4& v1,
|
||||
const Double k2, const Vector4& v2,
|
||||
const Double k3, const Vector4& v3);
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& ost, const Vector4& v);
|
||||
|
||||
} /* namespace basics */
|
||||
} /* namespace charles */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue