在這里你可以看到向量 AB。
目標:使向量 AC 找出 α
問題:要找出角度 α,我首先需要第二個向量 AC,它必須指向 190°,并且與 AB 的單位向量具有相同的長度。如何創建該向量?
A = (5, 10)
B = (10, 5)
distance = np.array([B[0] - A[0], A[1] - B[1]]) # Vector from A to B
unit_vector = distance / np.linalg.norm(distance) # unit vector
# Need to make Vector AC here
# Get angle between vector AB and vector AC
AB = unit_vector(unit_vector)
AC = unit_vector(c)
print(np.arccos(np.clip(np.dot(AB, AC), -1.0, 1.0)))

uj5u.com熱心網友回復:
好的,看看這個。鑒于您的觀點(5,10)和(10,5):
C:\tmp>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
## Find the angle to AB using traditional 0-to-the-right axes.
>>> math.atan2(-5,5)
-0.7853981633974483
## Convert to degrees.
>>> math.atan2(-5,5) * 180 / math.pi
-45.0
## Subtract 90 to shift the 0 point to the north
>>> math.atan2(-5,5) * 180 / math.pi - 90
-135.0
## Modulo 360 to make it positive
>>> (math.atan2(-5,5) * 180 / math.pi - 90) % 360
225.0
## Subtract 190, and we get the value for the angle alpha.
>>> (math.atan2(-5,5) * 180 / math.pi - 90) % 360 - 190
35.0
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/424820.html
下一篇:吐出錯誤數字的斐波那契數列
