Skip to content

Commit

Permalink
Added edge::calc_angle()
Browse files Browse the repository at this point in the history
Moved interior angle calculation to a separate function within the edge
class. This seems more elegant.
  • Loading branch information
Pseudomanifold committed Feb 14, 2011
1 parent 999ef1c commit 628ca3c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
34 changes: 33 additions & 1 deletion edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

#include <iostream>
#include <cassert>
#include <cmath>

#include "edge.h"

Expand Down Expand Up @@ -222,4 +222,36 @@ void edge::set_on_boundary(bool boundary)
this->boundary = boundary;
}

/*!
* Given another edge that is assumed to share one vertex with the current
* edge, calculate the interior angle between these two edges.
*
* @warning The result is undefined if both edges do _not_ share a common
* vertex.
*
* @return Interior angle between edge e and current edge
*/

double edge::calc_angle(const edge* e) const
{
// Check that both edges point into the _same_ direction -- otherwise
// the wrong angle would be calculated.

if( this->get_u() == e->get_u() ||
this->get_v() == e->get_v())
{
v3ctor a = this->get_u()->get_position() - this->get_v()->get_position();
v3ctor b = e->get_u()->get_position() - e->get_v()->get_position();

return(acos(a.normalize()*b.normalize()));
}
else
{
v3ctor a = this->get_u()->get_position() - this->get_v()->get_position();
v3ctor b = e->get_v()->get_position() - e->get_u()->get_position(); // swap second edge

return(acos(a.normalize()*b.normalize()));
}
}

} // end of namespace "psalm"
1 change: 1 addition & 0 deletions edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class edge
void set_on_boundary(bool boundary = true);

double calc_length() const;
double calc_angle(const edge* e) const;

private:

Expand Down

0 comments on commit 628ca3c

Please sign in to comment.