1. Understanding 3D Coordinates
In 3D space, each point P(x, y, z) is represented by three values where:
x
is the position on the X-axis (left-right)
y
is the position on the Y-axis (front-back)
z
is the position on the Z-axis (up-down)
Example:
A point A(2, 3, 4) means:
2. What is a Vector in 3D?
A vector in 3D space has:
A 3D vector is written as:
v=(a,b,c) Where a
, b
, and c
are the components along x, y, and z.
3. Vector from Two Points
To find a vector from point A to point B:
AB=(xb−xa,yb−ya,zb−za) Example:
Let A = (1, 2, 3) and B = (4, 6, 9). Then
AB=(4−1,6−2,9−3)=(3,4,6) Python Code:
import numpy as np
A = np.array([1, 2, 3])
B = np.array([4, 6, 9])
vector_AB = B - A
print("Vector AB:", vector_AB)
Output:
2. Vector Magnitude (Length)
v=x2+y2+z2 Example:
v=(3,4,6)⇒v=32+42+62=61 Python Code:
magnitude = np.linalg.norm(vector_AB)
print("Magnitude of Vector AB:", magnitude)
5. Unit Vector
A unit vector has magnitude 1 and points in the same direction:
v^=vv Python Code:
unit_vector = vector_AB / magnitude
print("Unit vector in direction of AB:", unit_vector)
Output:
Unit vector in direction of AB: [0.38411064 0.51214752 0.76822128]
6. Dot Product of Two Vectors
A.B=xaxb+yayb+zazb Used to find the angle between vectors:
cosθ=∣A∣∣B∣A.B Python Code:
import numpy as np
A = np.array([1, 2, 3])
B = np.array([4, 5, 6])
dot_product = np.dot(A, B)
angle = np.arccos(dot_product / (np.linalg.norm(a) * np.linalg.norm(b)))
print("Dot product:", dot_product)
print("Angle (radians):", angle)
Output:
Dot product: 32
Angle (radians): 0.2257261285527342
7. Cross Product
A×B=ixaxbjyaybkzazb Python Code:
import numpy as np
A = np.array([1, 2, 3])
B = np.array([4, 5, 6])
cross_product = np.cross(A, B)
print("Cross product (perpendicular vector):", cross_product)
Output:
Cross product (perpendicular vector): [-3 6 -3]
8. Distance Between Two Points in 3D
D=(x2−x1)2+(y2−y1)2+(z2−z1)2 Python Code:
import numpy as np
A = np.array([1, 2, 3])
B = np.array([4, 5, 6])
distance = np.linalg.norm(B - A)
print("Distance between A and B:", distance)
Output:
Distance between A and B: 5.196152422706632
9. Visualizing 3D Vectors
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# origin
ax.quiver(0, 0, 0, a[0], a[1], a[2], color='blue', label='a')
ax.quiver(0, 0, 0, b[0], b[1], b[2], color='green', label='b')
ax.set_xlim([0, 5])
ax.set_ylim([0, 5])
ax.set_zlim([0, 5])
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.legend()
plt.show()
Output:
Keywords
3D coordinates
, vectors
, vector magnitude
, unit vector
, dot product
, cross product
, vector projection
, distance in 3D
, 3D space
, vector operations
, python vectors
, numpy vectors
, angle between vectors
, 3D visualization
, vector direction
, vector length
, 3D math
, linear algebra
, vector geometry
, vector representation
, nerd cafe