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};
222 AxisAngle(
const std::array<double, 3> &axis,
double angle) noexcept
223 : axis(axis), angle(angle) {}
226 operator std::pair<std::array<double, 3>,
double>()
const noexcept {
227 return {axis, angle};
230template <std::
size_t I>
232 static_assert(I < 2);
233 if constexpr (I == 0) {
259 mutable std::optional<std::array<double, 3>>
rot_;
260 mutable std::optional<std::array<std::array<double, 3>, 3>>
rmat_;
262 Rotation(
const std::optional<std::array<double, 3>> &rot,
263 const std::optional<std::array<std::array<double, 3>, 3>> &rmat)
264 : rot_(rot), rmat_(rmat) {}
273 static WEBCFACE_DLL std::array<std::array<double, 3>, 3>
274 eulerToMatrix(
const std::array<double, 3> &rot,
AxisSequence axis);
280 matrixToEuler(
const std::array<std::array<double, 3>, 3> &rmat,
290 static WEBCFACE_DLL std::array<std::array<double, 3>, 3>
291 quaternionToMatrix(
const std::array<double, 4> &quat);
297 matrixToQuaternion(
const std::array<std::array<double, 3>, 3> &rmat);
304 axisAngleToQuaternion(
const std::array<double, 3> &axis,
double angle);
310 quaternionToAxisAngle(
const std::array<double, 4> &quat);
313 : rot_({0, 0, 0}), rmat_({{
319 friend Rotation
rotFromEuler(
const std::array<double, 3> &rot,
322 rotFromMatrix(
const std::array<std::array<double, 3>, 3> &matrix);
329 [[deprecated(
"use rotEuler() or rot2D()")]]
330 std::array<double, 3>
rot()
const {
340 [[deprecated(
"use rotEuler() or rot2D()")]]
341 double rot(std::size_t index)
const {
342 return rotEuler().at(index);
349 [[deprecated(
"use rotEuler() or rot2D()")]]
350 std::array<double, 3> &
rot() {
352 rmat_ = std::nullopt;
361 [[deprecated(
"use rotEuler() or rot2D()")]]
362 double &
rot(std::size_t index) {
364 rmat_ = std::nullopt;
365 return rot_->at(index);
375 double rot2D()
const {
return rotEuler()[0]; }
383 std::array<double, 3>
385 if (axis == AxisSequence::ZYX) {
388 rot_.emplace(matrixToEuler(*rmat_, AxisSequence::ZYX));
392 return matrixToEuler(rotMatrix(), axis);
400 const std::array<std::array<double, 3>, 3> &
rotMatrix()
const {
403 rmat_.emplace(eulerToMatrix(*rot_, AxisSequence::ZYX));
411 double rotMatrix(std::size_t row, std::size_t col)
const {
412 return rotMatrix().at(row).at(col);
420 return matrixToQuaternion(rotMatrix());
496 *
this = *
this * target;
521 if (axis == AxisSequence::ZYX) {
522 return {rot, std::nullopt};
524 return {std::nullopt, Rotation::eulerToMatrix(rot, axis)};
540 return rotFromEuler(traits::arrayLikeToArray<3>(rot), axis);
550 return rotFromEuler(std::array<double, 3>{angle1, angle2, angle3}, axis);
563 return {std::nullopt, matrix};
582 typename R,
typename traits::ArrayLikeTrait<R>::ArrayLike = traits::TraitOk,
583 typename traits::ArraySizeTrait<R, 4>::SizeMatchOrDynamic = traits::TraitOk>
585 return rotFromQuat(traits::arrayLikeToArray<4>(quat));
600 return rotFromQuat(Rotation::axisAngleToQuaternion(axis, angle));
610 typename R,
typename traits::ArrayLikeTrait<R>::ArrayLike = traits::TraitOk,
611 typename traits::ArraySizeTrait<R, 3>::SizeMatchOrDynamic = traits::TraitOk>
675 [[deprecated(
"use Transform(pos, rotEuler(rot))")]]
693 [[deprecated(
"use Transform({x, y, z}, rotEuler(z, y, x))")]]
694 Transform(
double x,
double y,
double z,
double z_angle,
double y_angle,
696 :
Transform(std::array<double, 3>{x, y, z},
697 Rotation{std::array<double, 3>{z_angle, y_angle, x_angle},
704 [[deprecated(
"use translation(x, y) for translation-only transform")]]
712 using Rotation::rot2D;
713 using Rotation::rotAxisAngle;
714 using Rotation::rotEuler;
715 using Rotation::rotMatrix;
716 using Rotation::rotQuat;
741 return this->appliedTo(target);
756 return this->appliedTo(
Transform(target));
764 return this->appliedTo(target);
774 *
this = *
this * target;
801 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:255
bool operator!=(const Transform &other) const
Definition transform.h:509
std::array< double, 3 > & rot()
3次元の回転をオイラー角として取得・変更
Definition transform.h:350
AxisAngle rotAxisAngle() const
回転軸と角度として取得
Definition transform.h:431
double & rot(std::size_t index)
3次元の回転をZYX順のオイラー角として取得・変更
Definition transform.h:362
std::optional< std::array< double, 3 > > rot_
Definition transform.h:259
double rot(std::size_t index) const
3次元の回転をZYX順のオイラー角として取得
Definition transform.h:341
bool operator!=(const Rotation &other) const
Definition transform.h:506
const std::array< std::array< double, 3 >, 3 > & rotMatrix() const
回転行列を取得
Definition transform.h:400
std::array< double, 3 > rot() const
3次元の回転をオイラー角として取得
Definition transform.h:330
Rotation()
Definition transform.h:312
double rot2D() const
2次元の回転を取得
Definition transform.h:375
std::optional< std::array< std::array< double, 3 >, 3 > > rmat_
Definition transform.h:260
double rotMatrix(std::size_t row, std::size_t col) const
回転行列の要素を取得
Definition transform.h:411
Rotation(const std::optional< std::array< double, 3 > > &rot, const std::optional< std::array< std::array< double, 3 >, 3 > > &rmat)
Definition transform.h:262
Rotation & operator*=(const Rotation &target)
このRotationを別のRotationに適用した結果で置き換える
Definition transform.h:495
std::array< double, 3 > rotEuler(AxisSequence axis=AxisSequence::ZYX) const
3次元の回転をオイラー角として取得
Definition transform.h:384
std::array< double, 4 > rotQuat() const
クォータニオンとして取得
Definition transform.h:419
Rotation rotFromQuat(const std::array< double, 4 > &quat)
回転をクォータニオンから初期化
Definition transform.h:571
Rotation rotX(double rot)
X軸周りの回転
Definition transform.h:629
Rotation rotFromMatrix(const std::array< std::array< double, 3 >, 3 > &matrix)
回転を回転行列から初期化
Definition transform.h:562
bool operator==(const T &other, const InputRef &ref)
Definition text.h:574
Rotation rotY(double rot)
Y軸周りの回転
Definition transform.h:634
Rotation rotFromEuler(const std::array< double, 3 > &rot, AxisSequence axis=AxisSequence::ZYX)
回転をオイラー角から初期化
Definition transform.h:519
AxisSequence
オイラー角の回転順序
Definition transform.h:191
const auto & get(const AxisAngle &aa)
Definition transform.h:231
Rotation rotFromAxisAngle(const std::array< double, 3 > &axis, double angle)
回転を回転軸と角度から初期化
Definition transform.h:598
Transform identity()
移動なし、回転なしのTransform
Definition transform.h:831
Rotation rotZ(double rot)
Z軸周りの回転
Definition transform.h:642
Transform translation(const Point &pos)
平行移動のみのTransform
Definition transform.h:836
Rotation rot2D(double rot)
2次元の回転を初期化
Definition transform.h:624
Definition transform.h:219
double angle
Definition transform.h:221
AxisAngle(const std::array< double, 3 > &axis, double angle) noexcept
Definition transform.h:222
std::array< double, 3 > axis
Definition transform.h:220
Definition array_like.h:58
Definition array_like.h:75
#define WEBCFACE_DLL
Definition webcface-config.h:69
#define WEBCFACE_NS_END
Definition webcface-config.h:118
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:117