5#include "webcface/common/webcface-config.h"
25 std::array<double, 3>
pos_;
32 Point(
const std::array<double, 3> &pos = {0, 0, 0}) : pos_(pos) {}
37 Point(
const std::array<double, 2> &pos) : pos_({pos[0], pos[1], 0}) {}
42 Point(
double x,
double y,
double z = 0)
43 :
Point(std::array<double, 3>{x, y, z}) {}
53 typename traits::ArrayLikeTrait<R>::ArrayLike = traits::TraitOk,
54 typename traits::ArraySizeTrait<R, 3>::SizeMatchOrDynamic =
56 Point(
const R &pos) : pos_(traits::arrayLikeToArray<3>(pos)) {}
62 std::array<double, 3>
pos()
const {
return pos_; }
67 std::array<double, 3> &
pos() {
return pos_; }
73 double pos(std::size_t index)
const {
return pos_.at(index); }
79 double &
pos(std::size_t i) {
return pos_.at(i); }
87 pos_[0] + other.
pos_[0],
88 pos_[1] + other.
pos_[1],
89 pos_[2] + other.
pos_[2],
115 pos_[0] += other.
pos_[0];
116 pos_[1] += other.
pos_[1];
117 pos_[2] += other.
pos_[2];
130 return {pos_[0] * scalar, pos_[1] * scalar, pos_[2] * scalar};
137 return point * scalar;
153 return {pos_[0] / scalar, pos_[1] / scalar, pos_[2] / scalar};
225 mutable std::optional<std::array<double, 3>>
rot_;
226 mutable std::optional<std::array<std::array<double, 3>, 3>>
rmat_;
228 Rotation(
const std::optional<std::array<double, 3>> &rot,
229 const std::optional<std::array<std::array<double, 3>, 3>> &rmat)
230 : rot_(rot), rmat_(rmat) {}
239 static WEBCFACE_DLL std::array<std::array<double, 3>, 3>
240 eulerToMatrix(
const std::array<double, 3> &rot,
AxisSequence axis);
246 matrixToEuler(
const std::array<std::array<double, 3>, 3> &rmat,
256 static WEBCFACE_DLL std::array<std::array<double, 3>, 3>
257 quaternionToMatrix(
const std::array<double, 4> &quat);
263 matrixToQuaternion(
const std::array<std::array<double, 3>, 3> &rmat);
270 axisAngleToQuaternion(
const std::array<double, 3> &axis,
double angle);
275 static WEBCFACE_DLL std::pair<std::array<double, 3>,
double>
276 quaternionToAxisAngle(
const std::array<double, 4> &quat);
279 : rot_({0, 0, 0}), rmat_({{
285 friend Rotation
rotFromEuler(
const std::array<double, 3> &rot,
288 rotFromMatrix(
const std::array<std::array<double, 3>, 3> &matrix);
295 [[deprecated(
"use rotEuler() or rot2D()")]]
296 std::array<double, 3>
rot()
const {
306 [[deprecated(
"use rotEuler() or rot2D()")]]
307 double rot(std::size_t index)
const {
308 return rotEuler().at(index);
315 [[deprecated(
"use rotEuler() or rot2D()")]]
316 std::array<double, 3> &
rot() {
318 rmat_ = std::nullopt;
327 [[deprecated(
"use rotEuler() or rot2D()")]]
328 double &
rot(std::size_t index) {
330 rmat_ = std::nullopt;
331 return rot_->at(index);
341 double rot2D()
const {
return rotEuler()[0]; }
349 std::array<double, 3>
351 if (axis == AxisSequence::ZYX) {
354 rot_.emplace(matrixToEuler(*rmat_, AxisSequence::ZYX));
358 return matrixToEuler(rotMatrix(), axis);
366 const std::array<std::array<double, 3>, 3> &
rotMatrix()
const {
369 rmat_.emplace(eulerToMatrix(*rot_, AxisSequence::ZYX));
377 double rotMatrix(std::size_t row, std::size_t col)
const {
378 return rotMatrix().at(row).at(col);
386 return matrixToQuaternion(rotMatrix());
393 return quaternionToAxisAngle(rotQuat());
459 *
this = *
this * target;
484 if (axis == AxisSequence::ZYX) {
485 return {rot, std::nullopt};
487 return {std::nullopt, Rotation::eulerToMatrix(rot, axis)};
503 return rotFromEuler(traits::arrayLikeToArray<3>(rot), axis);
513 return rotFromEuler(std::array<double, 3>{angle1, angle2, angle3}, axis);
526 return {std::nullopt, matrix};
545 typename R,
typename traits::ArrayLikeTrait<R>::ArrayLike = traits::TraitOk,
546 typename traits::ArraySizeTrait<R, 4>::SizeMatchOrDynamic = traits::TraitOk>
548 return rotFromQuat(traits::arrayLikeToArray<4>(quat));
563 return rotFromQuat(Rotation::axisAngleToQuaternion(axis, angle));
573 typename R,
typename traits::ArrayLikeTrait<R>::ArrayLike = traits::TraitOk,
574 typename traits::ArraySizeTrait<R, 3>::SizeMatchOrDynamic = traits::TraitOk>
638 [[deprecated(
"use Transform(pos, rotEuler(rot))")]]
656 [[deprecated(
"use Transform({x, y, z}, rotEuler(z, y, x))")]]
657 Transform(
double x,
double y,
double z,
double z_angle,
double y_angle,
659 :
Transform(std::array<double, 3>{x, y, z},
660 Rotation{std::array<double, 3>{z_angle, y_angle, x_angle},
667 [[deprecated(
"use translation(x, y) for translation-only transform")]]
675 using Rotation::rot2D;
676 using Rotation::rotAxisAngle;
677 using Rotation::rotEuler;
678 using Rotation::rotMatrix;
679 using Rotation::rotQuat;
704 return this->appliedTo(target);
719 return this->appliedTo(
Transform(target));
727 return this->appliedTo(target);
737 *
this = *
this * target;
764 return this->appliedTo(target);
3次元 or 2次元の座標を表すクラス。
Definition transform.h:23
Point(const R &pos)
3次元座標を初期化
Definition transform.h:56
Point operator/(double scalar) const
x, y, z の各要素をスカラーで割ったPointを返す
Definition transform.h:152
double pos(std::size_t index) const
座標を取得
Definition transform.h:73
bool operator!=(const Point &other) const
Definition transform.h:171
friend Point operator*(double scalar, const Point &point)
x, y, z の各要素をスカラー倍したPointを返す
Definition transform.h:136
Point & operator/=(double scalar)
Definition transform.h:158
Point operator-() const
x, y, z の各要素の符号を反転したPointを返す
Definition transform.h:96
bool operator!=(const Transform &)=delete
Point operator+(const Point &other) const
2つのPointの x, y, z の各要素を加算したPointを返す
Definition transform.h:85
std::array< double, 3 > pos() const
3次元座標を取得
Definition transform.h:62
Point(const std::array< double, 3 > &pos={0, 0, 0})
3次元座標を初期化
Definition transform.h:32
Point & operator*=(double scalar)
Definition transform.h:142
Point operator-(const Point &other) const
Definition transform.h:110
double & pos(std::size_t i)
座標を取得・変更
Definition transform.h:79
std::array< double, 3 > pos_
Definition transform.h:25
Point & operator+=(const Point &other)
Definition transform.h:114
Point & operator-=(const Point &other)
Definition transform.h:123
Point(const std::array< double, 2 > &pos)
2次元座標を初期化
Definition transform.h:37
Point operator+() const
Definition transform.h:103
Point operator*(double scalar) const
x, y, z の各要素をスカラー倍したPointを返す
Definition transform.h:129
Point(double x, double y, double z=0)
2or3次元座標を初期化
Definition transform.h:42
bool operator==(const Transform &)=delete
std::array< double, 3 > & pos()
3次元座標を取得・変更
Definition transform.h:67
3次元の回転を表すクラス
Definition transform.h:221
bool operator!=(const Transform &other) const
Definition transform.h:472
std::array< double, 3 > & rot()
3次元の回転をオイラー角として取得・変更
Definition transform.h:316
std::pair< std::array< double, 3 >, double > rotAxisAngle() const
回転軸と角度として取得
Definition transform.h:392
double & rot(std::size_t index)
3次元の回転をZYX順のオイラー角として取得・変更
Definition transform.h:328
std::optional< std::array< double, 3 > > rot_
Definition transform.h:225
double rot(std::size_t index) const
3次元の回転をZYX順のオイラー角として取得
Definition transform.h:307
bool operator!=(const Rotation &other) const
Definition transform.h:469
const std::array< std::array< double, 3 >, 3 > & rotMatrix() const
回転行列を取得
Definition transform.h:366
std::array< double, 3 > rot() const
3次元の回転をオイラー角として取得
Definition transform.h:296
Rotation()
Definition transform.h:278
double rot2D() const
2次元の回転を取得
Definition transform.h:341
std::optional< std::array< std::array< double, 3 >, 3 > > rmat_
Definition transform.h:226
double rotMatrix(std::size_t row, std::size_t col) const
回転行列の要素を取得
Definition transform.h:377
Rotation(const std::optional< std::array< double, 3 > > &rot, const std::optional< std::array< std::array< double, 3 >, 3 > > &rmat)
Definition transform.h:228
Rotation & operator*=(const Rotation &target)
このRotationを別のRotationに適用した結果で置き換える
Definition transform.h:458
std::array< double, 3 > rotEuler(AxisSequence axis=AxisSequence::ZYX) const
3次元の回転をオイラー角として取得
Definition transform.h:350
std::array< double, 4 > rotQuat() const
クォータニオンとして取得
Definition transform.h:385
Rotation rotFromQuat(const std::array< double, 4 > &quat)
回転をクォータニオンから初期化
Definition transform.h:534
Rotation rotX(double rot)
X軸周りの回転
Definition transform.h:592
Rotation rotFromMatrix(const std::array< std::array< double, 3 >, 3 > &matrix)
回転を回転行列から初期化
Definition transform.h:525
bool operator==(const T &other, const InputRef &ref)
Definition text.h:566
Rotation rotY(double rot)
Y軸周りの回転
Definition transform.h:597
Rotation rotFromEuler(const std::array< double, 3 > &rot, AxisSequence axis=AxisSequence::ZYX)
回転をオイラー角から初期化
Definition transform.h:482
AxisSequence
オイラー角の回転順序
Definition transform.h:191
Rotation rotFromAxisAngle(const std::array< double, 3 > &axis, double angle)
回転を回転軸と角度から初期化
Definition transform.h:561
Transform identity()
移動なし、回転なしのTransform
Definition transform.h:794
Rotation rotZ(double rot)
Z軸周りの回転
Definition transform.h:605
Transform translation(const Point &pos)
平行移動のみのTransform
Definition transform.h:799
Rotation rot2D(double rot)
2次元の回転を初期化
Definition transform.h:587
Definition array_like.h:58
Definition array_like.h:75
#define WEBCFACE_DLL
Definition webcface-config.h:60
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103