前提
Mediapipe(動画から3次元の座標情報を抽出してくれるソリューション)を使って関節の位置を動画から取得し、Three.js上に表現する仕組みを考えています。
間接の位置の取得はできましたが、各関節の間(例えば股関節から膝)の角度を求める方法がわからず困っています。
※求めた角度を使ってアニメーションを付与する予定です。
実現したいこと
以下のような形式で各関節の位置情報は取得できています。
間接A(X座標1、Y座標1、Z座標1)
間接B(X座標2、Y座標2、Z座標2)
この時、最終的にPythonで間接Aから間接Bまでのクォータニオンを求めたいです。
試したこと
間接AとBのオイラー角を求め、クォータニオンに変換すればいいのかと思い、原点と原点から移動した先の座標で実験してみました。
願わくば一番下のrot_quatで必要なクォータニオンを求められるかと思ったのですが、根本的に何か違うのか求められませんでした。。。
import numpy as np from scipy.spatial.transform import Rotation # Rotation Around X axis : 変数1(y,z)×変数2(y,z) xAxisArg1 = np.array([1,1]) #移動先の座標 xAxisArg2 = np.array([0,0]) #原点の座標 xAxisVec = xAxisArg1 - xAxisArg2 xAxisTanRad = np.arctan2(xAxisVec[0], xAxisVec[1]) # Rotation Around Y axis : 変数1(x,z)×変数2(x,z) yAxisArg1 = np.array([1,1]) yAxisArg2 = np.array([0,0]) yAxisVec = yAxisArg1 - yAxisArg2 yAxisTanRad = np.arctan2(yAxisVec[0], yAxisVec[1]) # Rotation Around Z axis : 変数1(x,y)×変数2(x,y) zAxisArg1 = np.array([1,1]) zAxisArg2 = np.array([0,0]) zAxisVec = zAxisArg1 - zAxisArg2 zAxisTanRad = np.arctan2(zAxisVec[0], zAxisVec[1]) xAxisDegree = np.rad2deg(xAxisTanRad) yAxisDegree = np.rad2deg(yAxisTanRad) zAxisDegree = np.rad2deg(zAxisTanRad) # Create a rotation object from Euler angles specifying axes of rotation rot = Rotation.from_euler('xyz', [xAxisDegree,yAxisDegree,zAxisDegree], degrees=True) # Convert to quaternions rot_quat = rot.as_quat()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。