7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Python】座標上の3点からなる角度を計算

Last updated at Posted at 2020-12-23

点A,B,Cがなす角,∠ABC (点B周りの角度)の算出方法です.


# 点A,B,Cの座標(3次元座標上の場合)
a = np.array([0,1,2])
b = np.array([10,20,30])
c = np.array([5,7,9])

# ベクトルを定義
vec_a = a - b
vec_c = c - b

# コサインの計算
length_vec_a = np.linalg.norm(vec_a)
length_vec_c = np.linalg.norm(vec_c)
inner_product = np.inner(vec_a, vec_c)
cos = inner_product / (length_vec_a * length_vec_c)

# 角度(ラジアン)の計算
rad = np.arccos(cos)

# 弧度法から度数法(rad ➔ 度)への変換
degree = np.rad2deg(rad)
7
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?