[Python] Calculate the angle consisting of three points on the coordinates

This is the calculation method of the angle formed by points A, B, and C, and ∠ABC (angle around point B).


#Point A,B,C coordinates (on 3D coordinates)
a = np.array([0,1,2])
b = np.array([10,20,30])
c = np.array([5,7,9])

#Define vector
vec_a = a - b
vec_c = c - b

#Cosine calculation
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)

#Calculation of angle (radian)
rad = np.arccos(cos)

#Conversion from radians to degrees (rad ➔ degrees)
degree = np.rad2deg(rad)

Recommended Posts

[Python] Calculate the angle consisting of three points on the coordinates
Calculate the total number of combinations with python
Calculate the probability of outliers on a boxplot
At the time of python update on ubuntu
the zen of Python
[Python] Calculate the average value of the pixel value RGB of the object
Python points from the perspective of a C programmer
Calculate the regression coefficient of simple regression analysis with python
Put the latest version of Python on linux (Debian) on Chromebook
I tried the accuracy of three Stirling's approximations in python
The story of how the Python bottle worked on Sakura Internet
Calculate the square root of 2 in millions of digits with python
About the ease of Python
Handling of python on mac
Calculate the number of changes
About the features of Python
The Power of Pandas: Python
Read the coordinates of the plot on the graph with Python-matplotlib (super beginner)
[Python] I wrote the route of the typhoon on the map using folium
Let's measure the test coverage of pushed python code on GitHub.
Calculate the editing distance as an index of pronunciation similarity [python]
Tips: [Python] Calculate the average value of the specified area with bedgraph
Neighborhood search for a set of (geographical coordinates) points on a sphere
How to update the python version of Cloud Shell on GCP
[Python] A simple function to find the center coordinates of a circle
Get the number of readers of a treatise on Mendeley in Python
The story of Python and the story of NaN
[Python] The stumbling block of import
First Python 3 ~ The beginning of repetition ~
Existence from the viewpoint of Python
pyenv-change the python version of virtualenv
In the python command python points to python3.8
Change the Python version of Homebrew
[Python] Understanding the potential_field_planning of Python Robotics
Memorize the Python commentary on YouTube.
Review of the basics of Python (FizzBuzz)
Environment construction of python3.8 on mac
Calculate the previous month in Python
About the size of matplotlib points
Sakura Use Python on the Internet
About the basics list of Python basics
Learn the basics of Python ① Beginners
Get the width of the div on the server side with Selenium + PhantomJS + Python
Approximation of distance between two points on the surface of a spheroid (on the surface of the earth)
[Python] Yuriko Koike Calculate the number of votes you need exactly [matplotlib]
Calculate the shortest route of a graph with Dijkstra's algorithm and Python
Calculate the probability of being a squid coin with Bayes' theorem [python]
You can see the transition of points in the J League on the graph!
Check the behavior of destructor in Python
[Python3] Understand the basics of Beautiful Soup
Pass the path of the imported python module
Investigate the effect of outliers on correlation
Check the existence of the file with python
About the virtual environment of python version 3.7
Let Python calculate Euler-Lagrange's equation of motion
[Python3] Rewrite the code object of the function
Post the subject of Gmail on twitter
I didn't know the basics of Python
The result of installing python in Anaconda
[Python] Try pydash of the Python version of lodash
[python] Checking the memory consumption of variables