Add generic ort(vector) implementation
This commit is contained in:
parent
bd861a13c7
commit
dc0f08e5c3
1 changed files with 34 additions and 6 deletions
|
|
@ -234,12 +234,6 @@ namespace psemek::geom
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: generic implementation (shares internals with det)
|
// TODO: generic implementation (shares internals with det)
|
||||||
template <typename T>
|
|
||||||
vector<T, 2> ort(vector<T, 2> const & v0)
|
|
||||||
{
|
|
||||||
return {-v0[1], v0[0]};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
vector<T, 3> ort(vector<T, 3> const & v0, vector<T, 3> const & v1)
|
vector<T, 3> ort(vector<T, 3> const & v0, vector<T, 3> const & v1)
|
||||||
{
|
{
|
||||||
|
|
@ -250,6 +244,40 @@ namespace psemek::geom
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Any vector orthogonal to v
|
||||||
|
// N.B.: discontinuous in odd dimensions
|
||||||
|
template <typename T, std::size_t N>
|
||||||
|
vector<T, N> ort(vector<T, N> const & v)
|
||||||
|
{
|
||||||
|
vector<T, N> result;
|
||||||
|
if constexpr ((N % 2) == 0)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < N; i += 2)
|
||||||
|
{
|
||||||
|
result[i] = -v[i + 1];
|
||||||
|
result[i + 1] = v[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::size_t i = 0, j = 1;
|
||||||
|
|
||||||
|
for (std::size_t k = 1; k < N; ++k)
|
||||||
|
{
|
||||||
|
if (std::abs(v[k]) > std::abs(v[i]))
|
||||||
|
{
|
||||||
|
j = i;
|
||||||
|
i = k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = vector<T, N>::zero();
|
||||||
|
result[i] = -v[j];
|
||||||
|
result[j] = v[i];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
vector<T, 3> cross(vector<T, 3> const & v0, vector<T, 3> const & v1)
|
vector<T, 3> cross(vector<T, 3> const & v0, vector<T, 3> const & v1)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue