Robotic Mechanics and Modeling/Kinematics/Additional Examples for Vectors

From testwiki
Revision as of 17:49, 6 February 2020 by imported>AlexSanducu (β†’Examples for various Vector operations)
(diff) ← Older revision | Latest revision (diff) | Newer revision β†’ (diff)
Jump to navigation Jump to search

Example 1 (Spring 20 - Team 4)

Example: A particle has position vector 3,4,5𝗆. What is its distance from the origin(0,0,0)?

If that distance is instead changed to

12𝗆

, what is its new position vector?

%reset -f
import numpy as np
P = np.array([3,4,5])#Initial Position Vector
MagP = np.linalg.norm(P) #magnitude
print(MagP)

PUnit = P/MagP #Unit vector (Direction vector)
newPos = 12 #new distance
PNew = PUnit*newPos #Multiply unit direction vector by distance
MagPNew = np.linalg.norm(PNew) #check distance
print(PNew)
print(MagPNew)

The initial distance of the particle is outputted as

7.07𝗆

. The new vector is

5.09,6.79,8.49

, and the last line of code checks the new magnitude, which shows that the magnitude (or distance from the origin) is

12𝗆

as intended.

Example 2 (Team 5, Spring 20)

An Example of Representing the Cross Product of Two Vectors

An example of how to find the cross product of a vector π€πŽ and vector 𝐁𝐎 in IPython.

  1. Example: A triangle has 3 points. Point O at the origin (0,0), point A (3,3) and point B (5,0). Using vectors AO and BO, calculate the area of the triangle. The area of a triangle can be calculated using the following equation: 1/2 * π€πŽ x 𝐁𝐎


 
%reset -f
import numpy as np
AO = np.array([3,3])
BO = np.array([5,0])
Area = np.cross(BO,AO)*.5
print ("The area of the triangle is", (Area))

The area of the triangle is 7.5 m^2

Example 3 (Team 6, Spring 20)

Examples for various Vector operations

Python can handle many Vector Operations. This code presents examples of basic arithmetic, such as addition, subtraction, multiplication, and division. All of which are standard procedures. The more detailed syntax arises when a dot product is desired. For the code to understand the dot product of Q dot V the code must be written as "q.dot(v) ". This snippet of code also highlights the simplicity in assigning a variable equal to a scalar value and then implementation of that variable to multiply it by the vector.

%reset -f
from numpy import array
print("Vectors")
v = array([4, 6, 8])
print("V is",v)
q= array ([2, 7, 9])
print("Q is",q)
print("Vector Addition")
z = v+q
print("Z is V +Q Z:",z)
print("Vector Subtraction")
w =q-v
r =v-q
print("W is Q-V",w)
print("R is V minus Q",r)
print("Vector Mulitplication")
c = v*q
print("C is V*Q",c)
print("Vector Division")
d = q / v
print("D is q/v or (q1/v1,q2/v2,q3/v3)",d)
print("Vector Dot Product")
f = q.dot(v)
print("F is equal to q dot product times v",[f])
print("Vector Scalar Multiplication")
print("Variable s is equal to 5")
s = 5
g = s*q
print("G is s times the vector Q",g)