12#include <Eigen/Geometry>
30static inline double Clamp(
const double x,
const double min,
const double max)
58static inline Eigen::Matrix3d
RotationMatrix(
double sine,
double cosine,
int axis)
61 return CreateMatrix(1.0, 0.0, 0.0, 0.0, cosine, -sine, 0.0, sine, cosine);
64 return CreateMatrix(cosine, 0.0, sine, 0.0, 1.0, 0.0, -sine, 0.0, cosine);
66 return CreateMatrix(cosine, -sine, 0.0, sine, cosine, 0.0, 0.0, 0.0, 1.0);
76 double t =
sqrt(
R(0, 0) *
R(0, 0) +
R(0, 1) *
R(0, 1));
80 return -
atan2(
R(1, 2),
R(2, 2));
85 return -
atan2(
R(0, 1),
R(0, 0));
89 return -
atan2(-
R(2, 1),
R(1, 1));
109static inline Eigen::Vector3d
normalize(
const Eigen::Vector3d &
v)
113 double len =
v.norm();
114 return FuzzyZero(
len) ? Eigen::Vector3d(0, 0, 0) : Eigen::Vector3d(
v /
len);
117static inline double angle(
const Eigen::Vector3d &v1,
const Eigen::Vector3d &
v2)
125 double qy =
R(0, 2) -
R(2, 0);
126 double qw =
R(0, 0) +
R(1, 1) +
R(2, 2) + 1;
128 double tau = 2.0 *
atan2(qy, qw);
147 R =
R *
T.transpose();
156 double num = 2.0 * (1.0 +
R(1, 1));
163 return Eigen::Vector3d(0.0, tau, 1.0);
167 double ax = -
R(2, 1) *
num;
168 double az =
R(0, 1) *
num;
170 return Eigen::Vector3d(ax, tau, az);
176 double sine2 = ax * ax + az * az;
177 double cosine2 =
sqrt((sine2 >= 1.0) ? 0.0 : 1.0 - sine2);
180 Eigen::Matrix3d S(Eigen::Quaterniond(-cosine2, ax, 0.0, az));
187 Eigen::Vector3d delta = Eigen::Vector3d(
R(2, 1) -
R(1, 2),
R(0, 2) -
R(2, 0),
R(1, 0) -
R(0, 1));
189 double c =
safe_acos((
R(0, 0) +
R(1, 1) +
R(2, 2) - 1) / 2);
190 double l = delta.norm();
199static inline bool EllipseClamp(
double &ax,
double &az,
const double *amin,
const double *amax)
201 double xlim, zlim,
x,
z;
222 if (
x <= xlim &&
z <= zlim) {
226 x = std::min(
x, xlim);
227 z = std::min(
z, zlim);
230 double invx = 1.0 / (xlim * xlim);
231 double invz = 1.0 / (zlim * zlim);
233 if ((
x *
x * invx +
z *
z * invz) <= 1.0) {
244 x =
sqrt(1.0 / (invx + invz * rico * rico));
252 ax = (ax < 0.0) ? -
x :
x;
253 az = (az < 0.0) ? -
z :
z;
ATTR_WARN_UNUSED_RESULT const size_t num
static double EulerAngleFromMatrix(const Eigen::Matrix3d &R, int axis)
static void RemoveTwist(Eigen::Matrix3d &R)
static Eigen::Matrix3d CreateMatrix(double xx, double xy, double xz, double yx, double yy, double yz, double zx, double zy, double zz)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
static Eigen::Vector3d MatrixToAxisAngle(const Eigen::Matrix3d &R)
static const double IK_EPSILON
static double ComputeTwist(const Eigen::Matrix3d &R)
static double safe_acos(double f)
static double Clamp(const double x, const double min, const double max)
static Eigen::Matrix3d RotationMatrix(double sine, double cosine, int axis)
static Eigen::Matrix3d ComputeTwistMatrix(double tau)
static Eigen::Vector3d SphericalRangeParameters(const Eigen::Matrix3d &R)
static Eigen::Matrix3d ComputeSwingMatrix(double ax, double az)
static bool EllipseClamp(double &ax, double &az, const double *amin, const double *amax)
static bool FuzzyZero(double x)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
VecBase< float, D > normalize(VecOp< float, D >) RET
ccl_device_inline float2 fabs(const float2 a)
ccl_device_inline float3 atan2(const float3 y, const float3 x)