blob: fdec6948a2b89744d381606f84519736ef8fc0f5 [file] [log] [blame]
Ytai Ben-Tsvicbee7d42021-06-15 00:39:31 -07001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "media/Twist.h"
Andy Hung8702c312023-01-30 11:58:44 -080018#include <android-base/stringprintf.h>
Andy Hung9d197e72023-02-03 19:18:33 -080019#include "media/QuaternionUtil.h"
Ytai Ben-Tsvicbee7d42021-06-15 00:39:31 -070020
21namespace android {
22namespace media {
23
24Pose3f integrate(const Twist3f& twist, float dt) {
25 Eigen::Vector3f translation = twist.translationalVelocity() * dt;
26 Eigen::Vector3f rotationVector = twist.rotationalVelocity() * dt;
27 return Pose3f(translation, rotationVectorToQuaternion(rotationVector));
28}
29
30Twist3f differentiate(const Pose3f& pose, float dt) {
31 Eigen::Vector3f translationalVelocity = pose.translation() / dt;
32 Eigen::Vector3f rotationalVelocity = quaternionToRotationVector(pose.rotation()) / dt;
33 return Twist3f(translationalVelocity, rotationalVelocity);
34}
35
36std::ostream& operator<<(std::ostream& os, const Twist3f& twist) {
37 os << "translation: " << twist.translationalVelocity().transpose()
38 << " rotation vector: " << twist.rotationalVelocity().transpose();
39 return os;
40}
41
Andy Hung8702c312023-01-30 11:58:44 -080042std::string Twist3f::toString() const {
43 return base::StringPrintf("[%0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f]",
44 mTranslationalVelocity[0], mTranslationalVelocity[1], mTranslationalVelocity[2],
45 mRotationalVelocity[0], mRotationalVelocity[1], mRotationalVelocity[2]);
46}
47
Ytai Ben-Tsvicbee7d42021-06-15 00:39:31 -070048} // namespace media
49} // namespace android