49 const std::vector<double> &vec2,
50 std::vector<double> &result) {
51 result[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
52 result[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
53 result[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
58 for (
double value : vec) {
59 norm += value * value;
61 return std::sqrt(norm);
66 std::vector<double> &result) {
68 result.resize(vec.size());
69 for (
size_t i = 0; i < vec.size(); ++i) {
70 result[i] = vec[i] / norm;
76 const std::vector<double> &onto_vec,
77 std::vector<double> &result) {
81 result.resize(onto_vec.size());
82 for (
size_t i = 0; i < onto_vec.size(); ++i) {
83 result[i] = (dot / onto_vec_norm_sq) * onto_vec[i];
89 const std::vector<int> &vec2,
90 std::vector<int> &result) {
92 result[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
93 result[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
94 result[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
99 for (
int value : vec) {
100 norm += value * value;
102 return std::sqrt(norm);
107 std::vector<double> &result) {
109 result.resize(vec.size());
110 for (
size_t i = 0; i < vec.size(); ++i) {
111 result[i] =
static_cast<double>(vec[i]) / norm;
117 const std::vector<int> &onto_vec,
118 std::vector<double> &result) {
122 result.resize(onto_vec.size());
123 for (
size_t i = 0; i < onto_vec.size(); ++i) {
124 result[i] = (dot / onto_vec_norm_sq) * onto_vec[i];
void std_cross_product(const std::vector< double > &vec1, const std::vector< double > &vec2, std::vector< double > &result)
Compute the cross product of two 3D vectors.
void std_vector_projection(const std::vector< double > &vec, const std::vector< double > &onto_vec, std::vector< double > &result)
Compute the projection of one vector onto another.
double std_vector_norm(const std::vector< double > &vec)
Compute the Euclidean norm (magnitude) of a vector.
void std_vector_normalize(const std::vector< double > &vec, std::vector< double > &result)
Normalize a vector to have unit length.
T std_dot_product(const std::vector< T > &vec1, const std::vector< T > &vec2)
Compute the dot product of two vectors.