void Cube::ComputeArea() { //Extra credit to implement this glm::vec4 vertices[]{ { -.5f, -.5f, .5f, 1.f, }, { .5f, -.5f, .5f, 1.f, }, { -.5f, .5f, .5f, 1.f, }, { -.5f, -.5f, .5f, 1.f, }, }; glm::vec4 vertices_world[ 4 ]; for( int i = 0; i < 4; ++i ){ vertices_world[ i ] = transform.T() * vertices[ i ]; } glm::vec3 v01( vertices_world[ 1 ] - vertices_world[ 0 ] ); glm::vec3 v03( vertices_world[ 2 ] - vertices_world[ 0 ] ); glm::vec3 v04( vertices_world[ 3 ] - vertices_world[ 0 ] ); area = 0.f; area += glm::length( glm::cross( v01, v03 ) ); area += glm::length( glm::cross( v03, v04 ) ); area += glm::length( glm::cross( v04, v01 ) ); area *= 2.f; }
void DragRect::TrackPoints03(const DPoint& pt0, const DPoint& pt3) { // width constant, height variable, theta variable Vec2d v03(pt0, pt3); DPoint pt1 = v03.flip270().unit().scale(v01_.mag()).add(pt0); pt0_ = pt0; v01_ = Vec2d(pt0, pt1); v02_ = Vec2d(pt0, v03.add(pt1)); }
Real Pyramid5::volume () const { // The pyramid with a bilinear base has volume given by the // formula in: "Calculation of the Volume of a General Hexahedron // for Flow Predictions", AIAA Journal v.23, no.6, 1984, p.954- Node * node0 = this->get_node(0); Node * node1 = this->get_node(1); Node * node2 = this->get_node(2); Node * node3 = this->get_node(3); Node * node4 = this->get_node(4); // Construct Various edge and diagonal vectors Point v40 ( *node0 - *node4 ); Point v13 ( *node3 - *node1 ); Point v02 ( *node2 - *node0 ); Point v03 ( *node3 - *node0 ); Point v01 ( *node1 - *node0 ); // Finally, ready to return the volume! return (1./6.)*(v40*(v13.cross(v02))) + (1./12.)*(v02*(v01.cross(v03))); }