Python Encyclopedia for Academics
  • Course Outline
  • Artificial Intelligence
    • Data Science Foundation
      • Python Programming
        • Introduction and Basics
          • Variables
          • Print Function
          • Input From User
          • Data Types
          • Type Conversion
        • Operators
          • Arithmetic Operators
          • Relational Operators
          • Bitwise Operators
          • Logical Operators
          • Assignment Operators
          • Compound Operators
          • Membership Operators
          • Identity Operators
      • Numpy
        • Vectors, Matrix
        • Operations on Matrix
        • Mean, Variance, and Standard Deviation
        • Reshaping Arrays
        • Transpose and Determinant of Matrix
      • Pandas
        • Series and DataFrames
        • Slicing, Rows, and Columns
        • Operations on DataFrames
        • Different wayes to creat DataFrame
        • Read, Write Operations with CSV files
      • Matplotlib
        • Graph Basics
        • Format Strings in Plots
        • Label Parameters, Legend
        • Bar Chart, Pie Chart, Histogram, and Scatter Plot
  • Machine Learning Algorithms
    • Regression Analysis In ML
      • Regression Analysis in Machine Learning
      • Proof of Linear Regression Formulas
      • Simple Linear Regression Implementation
      • Multiple Linear Regression
      • Advertising Dataset Example
      • Bike Sharing Dataset
      • Wine Quality Dataset
      • Auto MPG Dataset
    • Classification Algorithms in ML
      • Proof of Logistic Regression
      • Simplified Mathematical Proof of SVM
      • Iris Dataset
  • Machine Learning Laboratory
    • Lab 1: Titanic Dataset
      • Predicting Survival on the Titanic with Machine Learning
    • Lab 2: Dow Jones Index Dataset
      • Dow Jones Index Predictions Using Machine Learning
    • Lab 3: Diabetes Dataset
      • Numpy
      • Pandas
      • Matplotlib
      • Simple Linear Regression
      • Simple Non-linear Regression
      • Performance Matrix
      • Preprocessing
      • Naive Bayes Classification
      • K-Nearest Neighbors (KNN) Classification
      • Decision Tree & Random Forest
      • SVM Classifier
      • Logistic Regression
      • Artificial Neural Network
      • K means Clustering
    • Lab 4: MAGIC Gamma Telescope Dataset
      • Classification in ML-MAGIC Gamma Telescope Dataset
    • Lab 5: Seoul Bike Sharing Demand Dataset
      • Regression in ML-Seoul Bike Sharing Demand Dataset
    • Lab 6: Medical Cost Personal Datasets
      • Predict Insurance Costs with Linear Regression in Python
    • Lab 6: Predict The S&P 500 Index With Machine Learning And Python
      • Predict The S&P 500 Index With Machine Learning And Python
  • Artificial Neural Networks
    • Biological Inspiration vs. Artificial Neurons
    • Review linear algebra and calculus essentials for ANNs
    • Activation Function
  • Mathematics
    • Pre-Calculus
      • Factorials
      • Roots of Polynomials
      • Complex Numbers
      • Polar Coordinates
      • Graph of a Function
    • Calculus 1
      • Limit of a Function
      • Derivative of Function
      • Critical Points
      • Indefinite Integrals
  • Calculus 2
    • 3D Coordinates and Vectors
    • Vectors and Vector Operations
    • Lines and Planes in Space (3D)
    • Partial Derivatives
    • Optimization Problems (Maxima/Minima) in Multivariable Functions
    • Gradient Vectors
  • Engineering Mathematics
    • Laplace Transform
  • Electrical & electronics Eng
    • Resistor
      • Series Resistors
      • Parallel Resistors
    • Nodal Analysis
      • Example 1
      • Example 2
    • Transient State
      • RC Circuit Equations in the s-Domain
      • RL Circuit Equations in the s-Domain
      • LC Circuit Equations in the s-Domain
      • Series RLC Circuit with DC Source
  • Computer Networking
    • Fundamental
      • IPv4 Addressing
      • Network Diagnostics
  • Cybersecurity
    • Classical Ciphers
      • Caesar Cipher
      • Affine Cipher
      • Atbash Cipher
      • Vigenère Cipher
      • Gronsfeld Cipher
      • Alberti Cipher
      • Hill Cipher
Powered by GitBook
On this page
  • 1. Understanding 3D Coordinates
  • 2. What is a Vector in 3D?
  • 3. Vector from Two Points
  • 2. Vector Magnitude (Length)
  • 5. Unit Vector
  • 6. Dot Product of Two Vectors
  • 7. Cross Product
  • 8. Distance Between Two Points in 3D
  • 9. Visualizing 3D Vectors
  • Keywords
  1. Calculus 2

3D Coordinates and Vectors

Nerd Cafe

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 units along X-axis

  • 3 units along Y-axis

  • 4 units along Z-axis

2. What is a Vector in 3D?

A vector in 3D space has:

  • Direction

  • Magnitude (length)

A 3D vector is written as:

v→=(a,b,c)\overrightarrow{v}=\left( a, b, c \right)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)\overrightarrow{AB}=\left( x_{b}-x_{a} \; , y_{b}-y_{a} \; , z_{b}-z_{a} \right)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)\overrightarrow{AB} =\left( 4−1,6−2,9−3 \right)=\left( 3,4,6 \right)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:

Vector AB: [3 4 6]

2. Vector Magnitude (Length)

∣v→∣=x2+y2+z2\left| \overrightarrow{v} \right|=\sqrt{x^{2}+y^{2}+z^{2}}​v​=x2+y2+z2​

Example:

v→=(3,4,6)⇒∣v→∣=32+42+62=61\overrightarrow{v}=(3,4,6)\Rightarrow \left| \overrightarrow{v} \right|=\sqrt{3^{2}+4^{2}+6^{2}}=\sqrt{61}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^=v→∣v→∣\hat{v}=\frac{\overrightarrow{v}}{\left| \overrightarrow{v} \right|}v^=​v​v​

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\overrightarrow{A}.\overrightarrow{B}=x_{a}x_{b}+y_{a}y_{b}+z_{a}z_{b}A.B=xa​xb​+ya​yb​+za​zb​

Used to find the angle between vectors:

cosθ=A→.B→∣A→∣∣B→∣cos\theta=\frac{\overrightarrow{A}.\overrightarrow{B}}{|\overrightarrow{A}||\overrightarrow{B}|}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→=∣ijkxayazaxbybzb∣\overrightarrow{A}\times \overrightarrow{B}=\begin{vmatrix} i & j & k \\ x_{a} & y_{a} & z_{a} \\ x_{b} & y_{b} & z_{b} \end{vmatrix}A×B=​ixa​xb​​jya​yb​​kza​zb​​​

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)2D=\sqrt{(x_{2}-x_{1})^{2}+(y_{2}-y_{1})^{2}+(z_{2}-z_{1})^{2}} 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

PreviousCalculus 2NextVectors and Vector Operations

Last updated 1 month ago