39 double ellipseExponent,
45 mHeightOfTopSurface(0.3 * height)
48 assert(numPoints > 1);
49 assert(ellipseExponent > 0.0);
59 unsigned dense_pts = 50000;
62 std::vector<double> cumulative_arc_length(dense_pts);
63 std::vector<c_vector<double, 2> > dense_locations(dense_pts);
66 double dense_spacing = (2.0 * M_PI) / (
double)dense_pts;
67 double cumulative_dist = 0.0;
68 double temp_sin, temp_cos;
71 cumulative_arc_length[0] = 0.0;
72 dense_locations[0][0] = width * 0.5;
73 dense_locations[0][1] = 0.0;
76 for (
unsigned point = 1; point < dense_pts; point++)
79 cumulative_dist += dense_spacing;
82 temp_cos = cos(cumulative_dist);
83 temp_sin = sin(cumulative_dist);
86 dense_locations[point][0] = copysign(pow(fabs(temp_cos), ellipseExponent), temp_cos) * width * 0.5;
87 dense_locations[point][1] = copysign(pow(fabs(temp_sin), ellipseExponent), temp_sin) * height * 0.5;
90 assert(fabs(dense_locations[point][0]) < width * 0.5 + 1e-10);
91 assert(fabs(dense_locations[point][1]) < height * 0.5 + 1e-10);
94 cumulative_arc_length[point] = cumulative_arc_length[point - 1] + norm_2(dense_locations[point] - dense_locations[point - 1]);
97 double total_arc_length = cumulative_arc_length[dense_pts - 1] + norm_2(dense_locations[dense_pts - 1] - dense_locations[0]);
100 cumulative_arc_length.push_back(total_arc_length);
101 dense_locations.push_back(dense_locations[0]);
108 unsigned dense_it = 0;
112 double target_arclength = 0.0;
116 mPoints[0] = dense_locations[0];
119 for (
unsigned point = 1; point < numPoints; point++)
123 while (cumulative_arc_length[dense_it] < target_arclength && dense_it < dense_pts)
129 assert(cumulative_arc_length[dense_it - 1] < target_arclength);
130 assert(cumulative_arc_length[dense_it] >= target_arclength);
133 interpolant = (target_arclength - cumulative_arc_length[dense_it - 1]) / (cumulative_arc_length[dense_it] - cumulative_arc_length[dense_it - 1]);
136 mPoints[point] = (1.0 - interpolant) * dense_locations[dense_it - 1] + interpolant * dense_locations[dense_it];
147 if (ellipseExponent < 1.0)
153 if (delta_x > delta_y)
158 for (
unsigned i = 1; i < numPoints; i++)
163 if (delta_x > delta_y)
171 if (i ==
unsigned(numPoints / 2.0))
183 c_vector<double, 2> offset;
184 offset[0] = width * 0.5 + botLeftX;
185 offset[1] = height * 0.5 + botLeftY;
190 for (
unsigned point = 0; point < numPoints; point++)
196 assert((
mPoints[point][0] > botLeftX - 1e-10) && (
mPoints[point][0] < botLeftX + width + 1e-10));
197 assert((
mPoints[point][1] > botLeftY - 1e-10) && (
mPoints[point][1] < botLeftY + height + 1e-10));