26double Sqr(
const double x) {
30double CrossProd(
const Vec2d& start_point,
const Vec2d& end_point_1,
const Vec2d& end_point_2) {
31 return (end_point_1 - start_point).CrossProd(end_point_2 - start_point);
34double InnerProd(
const Vec2d& start_point,
const Vec2d& end_point_1,
const Vec2d& end_point_2) {
35 return (end_point_1 - start_point).InnerProd(end_point_2 - start_point);
38double CrossProd(
const double x0,
const double y0,
const double x1,
const double y1) {
39 return x0 * y1 - x1 * y0;
42double InnerProd(
const double x0,
const double y0,
const double x1,
const double y1) {
43 return x0 * x1 + y0 * y1;
47 const double new_angle = std::fmod(angle, M_PI * 2.0);
48 return new_angle < 0 ? new_angle + M_PI * 2.0 : new_angle;
52 double a = std::fmod(angle + M_PI, 2.0 * M_PI);
59double AngleDiff(
const double from,
const double to) {
63int RandomInt(
const int s,
const int t,
unsigned int rand_seed) {
67 return s + rand_r(&rand_seed) % (t - s + 1);
70double RandomDouble(
const double s,
const double t,
unsigned int rand_seed) {
71 return s + (t - s) / 16383.0 * (rand_r(&rand_seed) & 16383);
75double Gaussian(
const double u,
const double std,
const double x) {
76 return (1.0 / std::sqrt(2 * M_PI *
std *
std)) * std::exp(-(x - u) * (x - u) / (2 *
std *
std));
79Eigen::Vector2d
RotateVector2d(
const Eigen::Vector2d& v_in,
const double theta) {
80 const double cos_theta = std::cos(theta);
81 const double sin_theta = std::sin(theta);
83 auto x = cos_theta * v_in.x() - sin_theta * v_in.y();
84 auto y = sin_theta * v_in.x() + cos_theta * v_in.y();
90 double r = std::sqrt(x * x + y * y);
91 double theta = std::atan2(y, x);
92 return std::make_pair(r, theta);
96 if (std::signbit(input_data)) {
97 input_data = -input_data;
103 if (input_data > 0) {
105 }
else if (input_data < 0) {
Math-related util functions.
double Sqr(const double x)
int RandomInt(const int s, const int t, unsigned int rand_seed)
Get a random integer between two integer values by a random seed.
int sign(double input_data)
double Gaussian(const double u, const double std, const double x)
double CrossProd(const Vec2d &start_point, const Vec2d &end_point_1, const Vec2d &end_point_2)
Cross product between two 2-D vectors from the common start point, and end at two other points.
double RandomDouble(const double s, const double t, unsigned int rand_seed)
Get a random double between two integer values by a random seed.
double WrapAngle(const double angle)
Wrap angle to [0, 2 * PI).
double InnerProd(const Vec2d &start_point, const Vec2d &end_point_1, const Vec2d &end_point_2)
Inner product between two 2-D vectors from the common start point, and end at two other points.
std::pair< double, double > Cartesian2Polar(double x, double y)
double AngleDiff(const double from, const double to)
Calculate the difference between angle from and to
double check_negative(double input_data)
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Eigen::Vector2d RotateVector2d(const Eigen::Vector2d &v_in, const double theta)