#include "MeshPrimitives.h" #include "MeshBuilder.h" #include #include std::unique_ptr MeshPrimitives::buildRectangleAsTriMesh() { VecPoints locations = { {0, 0}, {1, 0}, {1, 1}, {0, 1} }; EdgeIds edge_ids = { {0, 1}, {1, 2}, {2, 0}, {2, 3}, {3, 0} }; FaceIds face_ids = { {0, 1, 2}, {2, 3, 4} }; return MeshBuilder::buildTriMesh(locations, edge_ids, face_ids); } std::unique_ptr MeshPrimitives::buildRoundedRectangleAsTriMesh(double radius, double aspect_ratio, unsigned num_segments) { unsigned num_fans = 4; unsigned num_nodes_per_fan = num_segments + 2; VecPoints locations(num_fans * num_nodes_per_fan); double rect_start_x = radius; double rect_end_x = 1.0 - radius; double rect_end_y = 1.0 - radius; double delta_theta = (M_PI/4.0) / double (num_segments); double running_theta = 0; locations[0] = {rect_end_x, radius}; unsigned offset = 1; for (unsigned idx=0; idx<=num_segments; idx++) { locations[offset + idx] = {rect_end_x + radius*sin(running_theta), radius*(1.0 - cos(running_theta))}; running_theta += delta_theta; } offset += num_segments; locations[offset] = {rect_end_x, rect_end_y}; offset++; running_theta = 0; for (unsigned idx=0; idx<=num_segments;idx++) { locations[offset + idx] = {rect_end_x + radius*cos(running_theta), rect_end_y + radius*sin(running_theta)}; running_theta += delta_theta; } offset += num_segments; locations[offset] = {rect_start_x, rect_end_y}; offset ++; running_theta = 0; for (unsigned idx=0; idx<=num_segments;idx++) { locations[offset + idx] = {rect_start_x - radius*sin(running_theta), rect_end_y + radius*cos(running_theta)}; running_theta += delta_theta; } offset += num_segments; locations[offset] = {rect_start_x, radius}; offset++; running_theta = 0; for (unsigned idx=0; idx<=num_segments;idx++) { locations[offset + idx] = {rect_start_x - radius*cos(running_theta), radius *(1 - sin(running_theta))}; running_theta += delta_theta; } unsigned num_edges_per_fan = 2*num_segments + 1; unsigned num_inner_rect_edges = 3*num_fans; EdgeIds edge_ids(num_edges_per_fan*num_fans + num_inner_rect_edges + 1); // Fan edges for (unsigned jdx=0; jdx< num_fans; jdx++) { unsigned node_offset = jdx*num_nodes_per_fan; unsigned edge_offset = jdx*num_edges_per_fan; // Inner edges for(unsigned idx=0; idx<=num_segments; idx++) { edge_ids[edge_offset + idx] = {node_offset, node_offset + idx + 1}; } // Outer edges for(unsigned idx=0; idx MeshPrimitives::buildRectangleAsLineMesh() { VecPoints locations = { {0, 0}, {1, 0}, {1, 1}, {0, 1} }; EdgeIds edge_ids = { {0, 1}, {1, 2}, {2, 3}, {3, 0} }; return MeshBuilder::buildLineMesh(locations, edge_ids); } std::unique_ptr MeshPrimitives::buildExplodedGridAsTriMesh(unsigned numX, unsigned numY) { double delta_x = 1.0/double(numX); double delta_y = 1.0/double(numY); VecPoints locations (4 * numX * numY); double offset_x = delta_x/2.0; double offset_y = delta_y/2.0; for (unsigned idx=0; idx MeshPrimitives::buildExplodedGridAsLineMesh(unsigned numX, unsigned numY) { double delta_x = 1.0/double(numX); double delta_y = 1.0/double(numY); VecPoints locations (4 * numX * numY); double offset_x = delta_x/2.0; double offset_y = delta_y/2.0; for (unsigned idx=0; idx