Polygon Polygon::convexHullOfTwoCircles(const Position center1, const Position center2, const double radius, const int nVertices) { if (center1 == center2) return fromCircle(center1, radius, nVertices); Eigen::Vector2d centerToVertex, centerToVertexTemp; centerToVertex = center2 - center1; centerToVertex.normalize(); centerToVertex *= radius; grid_map::Polygon polygon; for (int j = 0; j < ceil(nVertices / 2.0); j++) { double theta = M_PI_2 + j * M_PI / (ceil(nVertices / 2.0) - 1); Eigen::Rotation2D<double> rot2d(theta); centerToVertexTemp = rot2d.toRotationMatrix() * centerToVertex; polygon.addVertex(center1 + centerToVertexTemp); } for (int j = 0; j < ceil(nVertices / 2.0); j++) { double theta = 3 * M_PI_2 + j * M_PI / (ceil(nVertices / 2.0) - 1); Eigen::Rotation2D<double> rot2d(theta); centerToVertexTemp = rot2d.toRotationMatrix() * centerToVertex; polygon.addVertex(center2 + centerToVertexTemp); } return polygon; }
complex double krectangle(const double center[2], const double axis[2], double angle, const double p[2]) { double p90[2]; p90[0] = -p[1]; p90[1] = p[0]; double prot[2]; rot2d(prot, p90, angle); complex double res = sinc(2. * M_PI * prot[0] * axis[0]) * sinc(2. * M_PI * prot[1] * axis[1]) * (axis[0] * axis[1]); return res * cexp(2.i * M_PI * (p90[0] * center[0] + p90[1] * center[1])) / sqrtf(2. * M_PI) * 2.; }
Polygon Polygon::fromCircle(const Position center, const double radius, const int nVertices) { Eigen::Vector2d centerToVertex(radius, 0.0), centerToVertexTemp; Polygon polygon; for (int j = 0; j < nVertices; j++) { double theta = j * 2 * M_PI / (nVertices - 1); Eigen::Rotation2D<double> rot2d(theta); centerToVertexTemp = rot2d.toRotationMatrix() * centerToVertex; polygon.addVertex(center + centerToVertexTemp); } return polygon; }
complex double kellipsis(const double center[2], const double axis[2], double angle, const double p[2]) { double p90[2]; p90[0] = -p[1]; p90[1] = p[0]; double prot[2]; rot2d(prot, p90, angle); double radius = sqrt(pow(prot[0] * axis[0], 2.) + pow(prot[1] * axis[1], 2.)); complex double res = jinc(2. * M_PI * radius) * (axis[0] * axis[1]); return res * cexp(2.i * M_PI * (p90[0] * center[0] + p90[1] * center[1])) / sqrtf(2. * M_PI) * 2.; }
complex double xrectangle(const double center[2], const double axis[2], double angle, const double p[2]) { double p90[2]; p90[0] = -p[1]; p90[1] = p[0]; double pshift[2]; pshift[0] = p90[0] + center[0]; pshift[1] = p90[1] + center[1]; double prot[2]; rot2d(prot, pshift, angle); double radius = fabs(prot[0] / axis[0]) + fabs(prot[1] / axis[1]); return (radius <= 1.) ? 1. : 0.; }
complex double xellipsis(const double center[2], const double axis[2], double angle, const double p[2]) { double p90[2]; p90[0] = -p[1]; p90[1] = p[0]; double pshift[2]; pshift[0] = p90[0] + center[0]; pshift[1] = p90[1] + center[1]; double prot[2]; rot2d(prot, pshift, angle); double radius = pow(prot[0] / axis[0], 2.) + pow(prot[1] / axis[1], 2.); return (radius <= 1.) ? 1. : 0.; }
complex double kellipsis3d(const double center[3], const double axis[3], double angle, const double p[3]) { double p90[3]; p90[0] = -p[1]; p90[1] = p[0]; p90[2] = p[2]; double pshift[3]; pshift[0] = p90[0] + center[0]; pshift[1] = p90[1] + center[1]; pshift[2] = p90[2] + center[2]; double prot[3]; rot2d(prot, pshift, angle); prot[2] = pshift[2]; double radius = sqrt(pow(prot[0] * axis[0], 2.) + pow(prot[1] * axis[1], 2.) + pow(prot[2] * axis[2], 2.)); complex double res = ksphere3(2. * M_PI * radius) * (axis[0] * axis[1] * axis[2]); return res * cexp(2.i * M_PI * (p90[0] * center[0] + p90[1] * center[1] + p90[2] * center[2])) / sqrtf(M_PI) * sqrtf(8.); }