From 628ca3caef621502ae6a266f0810dde50541a731 Mon Sep 17 00:00:00 2001 From: Bastian Rieck Date: Mon, 14 Feb 2011 14:44:04 +0100 Subject: [PATCH] Added `edge::calc_angle()` Moved interior angle calculation to a separate function within the edge class. This seems more elegant. --- edge.cpp | 34 +++++++++++++++++++++++++++++++++- edge.h | 1 + 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/edge.cpp b/edge.cpp index c482d69..722d768 100644 --- a/edge.cpp +++ b/edge.cpp @@ -4,7 +4,7 @@ */ #include -#include +#include #include "edge.h" @@ -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" diff --git a/edge.h b/edge.h index 337eb03..f43fdf6 100644 --- a/edge.h +++ b/edge.h @@ -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: