Skip to content

Commit

Permalink
added tensor2 norm and fixed equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
dellaert committed Oct 5, 2010
1 parent c0581cd commit 4169e08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion geometry/Tensor1Expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ namespace tensors {

template<class B>
bool equivalent(const Tensor1Expression<B, I> & q, double tol = 1e-9) const {
return ((*this) * (1.0 / norm())).equals(q * (1.0 / q.norm()), tol);
return ((*this) * (1.0 / norm())).equals(q * (1.0 / q.norm()), tol)
|| ((*this) * (-1.0 / norm())).equals(q * (1.0 / q.norm()), tol);
}

/** Check if two expressions are equal */
Expand Down
15 changes: 11 additions & 4 deletions geometry/Tensor2Expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,19 @@ namespace tensors {
return true;
}

// TODO: broken !!!! Should not treat Tensor1's separately: one scale only!
/** norm */
double norm() const {
double sumsqr = 0.0;
for (int i = 0; i < I::dim; i++)
for (int j = 0; j < J::dim; j++)
sumsqr += iter(i,j) * iter(i,j);
return sqrt(sumsqr);
}

template<class B>
bool equivalent(const Tensor2Expression<B, I, J> & q, double tol) const {
for (int j = 0; j < J::dim; j++)
if (!(*this)(j).equivalent(q(j), tol)) return false;
return true;
return ((*this) * (1.0 / norm())).equals(q * (1.0 / q.norm()), tol)
|| ((*this) * (-1.0 / norm())).equals(q * (1.0 / q.norm()), tol);
}

/** element access */
Expand Down

0 comments on commit 4169e08

Please sign in to comment.