1 /*
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"
18 #include <android-base/stringprintf.h>
19 #include "media/QuaternionUtil.h"
20
21 namespace android {
22 namespace media {
23
integrate(const Twist3f & twist,float dt)24 Pose3f 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
differentiate(const Pose3f & pose,float dt)30 Twist3f 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
operator <<(std::ostream & os,const Twist3f & twist)36 std::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
toString() const42 std::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
48 } // namespace media
49 } // namespace android
50