50 double pipe(
double* x, std::vector<double>* c) {
54 double polynom2(
double* x, std::vector<double>* c) {
55 return (*c)[0]*pow((*x),2) + (*c)[1]*((*x)) + (*c)[2];
58 double polynom3(
double* x, std::vector<double>* c) {
59 return (*c)[0]*pow((*x),3) + (*c)[1]*pow((*x),2) + (*c)[2]*((*x)) + (*c)[3];
62 double polynom4(
double* x, std::vector<double>* c) {
63 return (*c)[0]*pow((*x),4) + (*c)[1]*pow((*x),3)
64 + (*c)[2]*pow((*x),2) + (*c)[3]*((*x)) + (*c)[4];
67 double polynom5(
double* x, std::vector<double>* c) {
68 return (*c)[0]*pow((*x),5) + (*c)[1]*pow((*x),4) + (*c)[2]*pow((*x),3)
69 + (*c)[3]*pow((*x),2) + (*c)[4]*((*x)) + (*c)[5];
74 double gaussian(
double* x, std::vector<double>* c) {
75 return 1/(
SQRT2PI*(*c)[1])*exp(-0.5*pow(((*x)-(*c)[0])/(*c)[1], 2));
87 double polynom2D1(
double* x,
double* y, std::vector<double>* c) {
88 return (*c)[0]*(*x)*(*y) + (*c)[1]*((*x)) + (*c)[2]*((*x)) + (*c)[3];
92 double polynom2D2(
double* x,
double* y, std::vector<double>* c) {
93 return (*c)[0]*pow((*x),2)*pow((*y),2) + (*c)[1]*pow((*x),2)*(*y) + (*c)[2]*(*x)*pow((*y),2)
94 + (*c)[3]*pow((*x),2) + (*c)[4]*pow((*y),2) + (*c)[5]*(*x)*(*y) + (*c)[6]*((*x))
95 + (*c)[7]*((*x)) + (*c)[8];
103 Eigen::Vector3d v = q * Eigen::Vector3d::UnitX();
104 return ::atan2(v[1],v[0]);
108 double squared_length1 = v1.squaredNorm();
109 double squared_length2 = v2.squaredNorm();
110 double tmp = sqrt(squared_length1 * squared_length2);
111 double angle = acos(v1.dot(v2) / tmp);
120 dummy =
Vector(v1.y(), -v1.x(), v1.z());
122 dummy =
Vector(v1.x(), v1.z(), -v1.y());
124 *axis = dummy.cross(v2) / tmp;
126 *axis = v1.cross(v2) / tmp;
135 double _heading =
degToRad(euler_v[2]);
136 double _attitude =
degToRad(euler_v[1]);
137 double _bank =
degToRad(euler_v[0]);
138 double c1 = cos(_heading/2);
139 double s1 = sin(_heading/2);
140 double c2 = cos(_attitude/2);
141 double s2 = sin(_attitude/2);
142 double c3 = cos(_bank/2);
143 double s3 = sin(_bank/2);
147 q.w() = (double) (c1c2*c3 + s1s2*s3);
148 q.x() = (double) (c1c2*s3 - s1s2*c3);
149 q.y() = (double) (c1*s2*c3 + s1*c2*s3);
150 q.z() = (double) (s1*c2*c3 - c1*s2*s3);
151 return q.normalized();
154 Eigen::AngleAxisd(euler_v.x()/180.0*
M_PI,
155 Eigen::Vector3d::Unit(EULER_AXIS_1)) *
156 Eigen::AngleAxisd(euler_v.z()/180.0*
M_PI,
157 Eigen::Vector3d::Unit(EULER_AXIS_2)) *
158 Eigen::AngleAxisd(euler_v.y()/180.0*
M_PI,
159 Eigen::Vector3d::Unit(EULER_AXIS_3));
166 double sqw = value.w()*value.w();
167 double sqx = value.x()*value.x();
168 double sqy = value.y()*value.y();
169 double sqz = value.z()*value.z();
171 euler.
gamma =
radToDeg(atan2(2.*(value.x()*value.y()+value.z()*value.w()),
172 (sqx - sqy - sqz + sqw)));
174 euler.
alpha =
radToDeg(atan2(2.*(value.y()*value.z()+value.x()*value.w()),
175 (-sqx - sqy + sqz + sqw)));
177 double test = -2. * (value.x()*value.z() - value.y()*value.w());
178 test = (test > 1. ? 1. : (test < -1. ? -1. : test));
182 Vector yaw_roll_pitch = value.toRotationMatrix().eulerAngles(EULER_AXIS_1,
197 throw std::runtime_error(
"Argument t to Vector::slerp must be in range [-1, 1].");
200 double length1 = from.norm();
201 double length2 = to.norm();
202 double tmp = from.dot(to) / (length1 * length2);
204 tmp = (tmp < -1 ? -1 : (tmp > 1 ? 1: tmp));
205 double angle = acos(tmp);
212 if (from.x() * to.y() < from.y() * to.x())
217 if ((fabs(angle) <=
EPSILON) ||
220 ret =
lerp(from, to, t);
224 throw std::runtime_error(
"SLERP with 180 degrees is undefined.");
227 double f0 = ((length2 - length1) * t + length1) / ::sin(angle);
228 double f1 = ::sin(angle * (1-t)) / length1;
229 double f2 = ::sin(angle * t) / length2;
230 ret = ((from.array() * f1 + to.array() * f2) * f0).matrix();
236 if (t < 0 || t > 1) {
237 throw std::runtime_error(
"Argument t to Vector::lerp must be in range [0, 1]");
239 return (from.array() * (1-t) + to.array() * t).matrix();
249 *theta = acos(v.z() / (*r));
250 *phi = atan2(v.y(), v.x());
254 double a = v1.dot(v2);
255 double b = v2.dot(v2);
262 return Vector(r * sin(theta) * cos(phi),
263 r * sin(theta) * sin(phi),
268 v->x() = (*item)[
"x"];
269 v->y() = (*item)[
"y"];
270 v->z() = (*item)[
"z"];
275 (*item)[
"x"] = v->x();
276 (*item)[
"y"] = v->y();
277 (*item)[
"z"] = v->z();
281 q->w() = (*item)[
"w"];
282 q->x() = (*item)[
"x"];
283 q->y() = (*item)[
"y"];
284 q->z() = (*item)[
"z"];
289 (*item)[
"w"] = q->w();
290 (*item)[
"x"] = q->x();
291 (*item)[
"y"] = q->y();
292 (*item)[
"z"] = q->z();
296 (*item)[
"i00"] = inertia[0];
297 (*item)[
"i01"] = inertia[1];
298 (*item)[
"i02"] = inertia[2];
299 (*item)[
"i10"] = inertia[3];
300 (*item)[
"i11"] = inertia[4];
301 (*item)[
"i12"] = inertia[5];
302 (*item)[
"i20"] = inertia[6];
303 (*item)[
"i21"] = inertia[7];
304 (*item)[
"i22"] = inertia[8];
308 int range = pow(10, digits);
309 int r = rand() % range;
310 return r / (double)range * (max-min) + min;
322 double num = cos(2*
M_PI*u2)*sqrt(-2.*log(u1)) * std + mean;
324 return std::min(
std::max(num, low), high);
Vector slerp(const Vector &from, const Vector &to, double t)
Vector lerp(const Vector &from, const Vector &to, double t)
static const int EULER_AXIS_1
double angleBetween(const Vector &v1, const Vector &v2, Vector *axis)
Angle between two vectors.
Vector vectorFromSpherical(double r, double theta, double phi)
double random_number(double min, double max, int digits)
double degToRad(const double &d)
converts an angle given in degrees to radians.
void inertiaTensorToConfigItem(ConfigItem *item, double *inertia)
static const int EULER_AXIS_2
ApproximationFunction getApproximationFunctionFromString(std::string s)
sRotation quaternionTosRotation(const Quaternion &value)
bool vectorFromConfigItem(ConfigItem *item, Vector *v)
double radToDeg(const double &r)
converts an angle given in radians to degrees.
bool quaternionFromConfigItem(ConfigItem *item, Quaternion *q)
static const int EULER_AXIS_3
void vectorToConfigItem(ConfigItem *item, Vector *v)
Base object of the configmaps library!
void vectorToSpherical(const Vector &v, double *r, double *theta, double *phi)
Quaternion eulerToQuaternion(const Vector &euler_v)
double polynom3(double *x, std::vector< double > *c)
double polynom2(double *x, std::vector< double > *c)
ApproximationFunction2D getApproximationFunction2DFromString(std::string s)
Vector getProjection(const Vector &v1, const Vector &v2)
void quaternionToConfigItem(ConfigItem *item, Quaternion *q)
double getYaw(const Quaternion &q)
Copyright 2012, DFKI GmbH Robotics Innovation Center.
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vector
Eigen::Quaternion< double, Eigen::DontAlign > Quaternion
double random_normal_number(double mean, double std, double low, double high)
double polynom2D1(double *x, double *y, std::vector< double > *c)
double polynom5(double *x, std::vector< double > *c)
double pipe(double *x, std::vector< double > *c)
double gaussian(double *x, std::vector< double > *c)
double polynom4(double *x, std::vector< double > *c)
double polynom2D2(double *x, double *y, std::vector< double > *c)