Skip to content

Commit

Permalink
Added face::calc_area()
Browse files Browse the repository at this point in the history
Currently implemented for triangular faces only. I am not sure whether a
general implementation will be necessary.
  • Loading branch information
Pseudomanifold committed Feb 14, 2011
1 parent 9cf2c6f commit 37ec2b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,22 @@ void face::set_on_boundary(bool boundary)
this->boundary = boundary;
}

/*!
* Calculates the area of the face. Currently, this only works if the face
* is triangular.
*
* @return Unsigned area of the face; negative values indicate an error
*/

double face::calc_area() const
{
if(this->num_vertices() != 3)
return(-1.0);

v3ctor A = V[1]->get_position() - V[0]->get_position();
v3ctor B = V[2]->get_position() - V[0]->get_position();

return(0.5*(A|B).length());
}

} // end of namespace "psalm"
2 changes: 2 additions & 0 deletions face.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class face

void reconstruct_from_edges();

double calc_area() const;

private:
std::vector<directed_edge> E;
std::vector<vertex*> V;
Expand Down

0 comments on commit 37ec2b0

Please sign in to comment.