Python | Triangle Law of Vector Addition (Matplotlib Arrow Example)

Here, we are going to learn about the triangle law of vector addition (matplotlib arrow example) and its Python implementation.
Submitted by Anuj Singh, on August 04, 2020

There is a law of vector addition in physics, that is commonly known as the triangular law of vector addition and in this article, we are going to draw the vector diagram for the same using arrows in python. This example illustrates one of the very common and good examples of applications of arrows in real life.

#Vector A
plt.arrow(0.05, 0.15, 0.4, 0.15, head_width=0.02, head_length=0.04)

#Vector B
plt.arrow(0.45, 0.3, 0.2, 0.5, head_width=0.02, head_length=0.04)

#Sum of the Vectors as A + B
plt.arrow(0.05, 0.15, 0.59, 0.65, head_width=0.02, head_length=0.04)

Illustration:

Python | Triangle Law of Vector Addition (Matplotlib Arrow Example)

Python code for triangle law of vector addition (matplotlib arrow example)

import matplotlib.pyplot as plt

plt.figure()
plt.arrow(0.05, 0.15, 0.4, 0.15, head_width=0.02, head_length=0.04)
plt.text(0.2, 0.14, 'Vector A')

plt.arrow(0.45, 0.3, 0.2, 0.5, head_width=0.02, head_length=0.04)
plt.text(0.6, 0.6, 'Vector B')

plt.arrow(0.05, 0.15, 0.59, 0.65, head_width=0.02, head_length=0.04)
plt.text(0.28, 0.45, 'Vector A + Vector B', rotation=40)


plt.title('Triangle Law of Vector Addition')
plt.show()

Output:

Output is as figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.