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
  • PART 1: Vectors in 3D
  • PART 2: Line in Space
  • PART 3: Plane in Space
  • PART 4: Angle Between Two Lines
  • PART 5: Intersection of Line and Plane
  • PART 6: Distance from a Point to a Plane
  • PART 7: Distance Between Parallel Planes
  • PART 8: Angle Between Line and Plane
  • PART 9: Line of Intersection of Two Planes
  • Keywords
  1. Calculus 2

Lines and Planes in Space (3D)

Nerd Cafe

PART 1: Vectors in 3D

A. Position Vector

A position vector points from the origin to a point in space. If a point P(x, y, z), then the position vector is:

r→=xi^+yj^+zk^\overrightarrow{r}=x\hat{i}+y\hat{j}+z\hat{k}r=xi^+yj^​+zk^

B. Vector Between Two Points

If A(x1,y1,z1) and B(x2,y2,z2):

AB→=(xb−xa,yb−ya,zb−za)\overrightarrow{AB}=(x_{b}-x_{a},y_{b}-y_{a},z_{b}-z_{a})AB=(xb​−xa​,yb​−ya​,zb​−za​)

C. Python Example:

import numpy as np

A = np.array([1, 2, 3])
B = np.array([4, 0, 5])

AB = B - A
print("Vector AB:", AB)

D. Output:

Vector AB: [ 3 -2  2]

PART 2: Line in Space

A. Vector Equation of a Line

A line passing through point

r0→=(x0,y0,z0)\overrightarrow{r_{0}}=(x_{0},y_{0},z_{0})r0​​=(x0​,y0​,z0​)

with direction vector

v→=(a,b,c)\overrightarrow{v}=(a,b,c)v=(a,b,c)

is:

r(t)→=r0→+tv→\overrightarrow{r(t)}=\overrightarrow{r_{0}}+t\overrightarrow{v}r(t)​=r0​​+tv

This gives:

x=x0+aty=y0+btz=z0+ct\begin{matrix} x=x_{0}+at \\ y=y_{0}+bt \\ z=z_{0}+ct \end{matrix}x=x0​+aty=y0​+btz=z0​+ct​

B. Python Example:

import matplotlib.pyplot as plt

# Line: point + t * direction
r0 = np.array([1, 2, 1])
v = np.array([2, 1, 3])
t = np.linspace(-5, 5, 100)

line = r0[:, None] + v[:, None] * t

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(line[0], line[1], line[2], label='Line in 3D')
ax.scatter(*r0, color='red', label='Point r0')
ax.quiver(*r0, *v, length=1, color='green', label='Direction vector')
ax.legend()
plt.show()

C. Output:

PART 3: Plane in Space

A. General Equation of a Plane

Given a point

P0=(x0,y0,z0)P_{0}=(x_{0},y_{0},z_{0})P0​=(x0​,y0​,z0​)

and normal vector

n→=(a,b,c)\overrightarrow{n}=(a,b,c)n=(a,b,c)

then:

a(x−x0)+b(y−y0)+c(z−z0)=0a(x-x_{0})+b(y-y_{0})+c(z-z_{0})=0a(x−x0​)+b(y−y0​)+c(z−z0​)=0

Which simplifies to:

ax+by+cz=dax+by+cz=dax+by+cz=d

where:

d=ax0+by0+cz0d=ax_{0}+by_{0}+cz_{0}d=ax0​+by0​+cz0​

B. Python Example:

from sympy import symbols, Eq, solve

x, y, z = symbols('x y z')
point = np.array([1, 2, 3])
normal = np.array([2, -1, 4])

# Plane equation: a(x-x0) + b(y-y0) + c(z-z0) = 0
a, b, c = normal
x0, y0, z0 = point

plane_eq = Eq(a*(x - x0) + b*(y - y0) + c*(z - z0), 0)
print("Plane Equation:", plane_eq)

C. Output:

Plane Equation: Eq(2*x - y + 4*z - 12, 0)

PART 4: Angle Between Two Lines

Given direction vectors v1,v2​​:

cosθ=v1→.v2→∣v1→∣∣v2→∣cos\theta=\frac{\overrightarrow{v_{1}}.\overrightarrow{v_{2}}}{|\overrightarrow{v_{1}}||\overrightarrow{v_{2}}|}cosθ=∣v1​​∣∣v2​​∣v1​​.v2​​​

A. Python Example:

v1 = np.array([1, 2, 3])
v2 = np.array([4, 5, 6])

cos_theta = np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2))
theta_rad = np.arccos(cos_theta)
theta_deg = np.degrees(theta_rad)

print("Angle between lines (degrees):", theta_deg)

B. Output:

Angle between lines (degrees): 12.933154491899135

PART 5: Intersection of Line and Plane

To find intersection:

  1. Substitute parametric equations of the line into the plane equation.

  2. Solve for t.

  3. Plug t back into the line to find the point.

A. Python Example:

# Line: r(t) = [1 + 2t, 2 + t, 3 + 4t]
x, y, z, t = symbols('x y z t')
line = [1 + 2*t, 2 + t, 3 + 4*t]

# Plane: 2x - y + 4z - 10 = 0
plane_eq = Eq(2*line[0] - line[1] + 4*line[2] - 10, 0)
t_val = solve(plane_eq, t)[0]

intersection = [coord.subs(t, t_val) for coord in line]
print("Intersection point:", intersection)

B. Output:

Intersection point: [15/19, 36/19, 49/19]

PART 6: Distance from a Point to a Plane

Given point

P=(x1,y1,z1)P=(x_{1},y_{1},z_{1})P=(x1​,y1​,z1​)

and plane

ax+by+cz+d=0ax+by+cz+d=0ax+by+cz+d=0

so:

Distance=∣ax1+by1+cz1+d∣a2+b2+c2Distance=\frac{|ax_{1}+by_{1}+cz_{1}+d|}{\sqrt{a^{2}+b^{2}+c^{2}}}Distance=a2+b2+c2​∣ax1​+by1​+cz1​+d∣​

A. Python Example:

point = np.array([2, 3, 4])
normal = np.array([2, -1, 4])
d = -10  # from plane equation: 2x - y + 4z - 10 = 0 → d = -10

numerator = abs(np.dot(normal, point) + d)
denominator = np.linalg.norm(normal)

distance = numerator / denominator
print("Distance from point to plane:", distance)

B. Output:

Distance from point to plane: 1.5275252316519468

PART 7: Distance Between Parallel Planes

If both planes have the same normal vector:

ax+by+cz+d1=0    and    ax+by+cz+d2=0ax+by+cz+d_{1}=0\;\;and\;\;ax+by+cz+d_{2}=0ax+by+cz+d1​=0andax+by+cz+d2​=0

so:

Distance=∣d2−d1∣a2+b2+c2Distance=\frac{|d_{2}-d_{1}|}{\sqrt{a^{2}+b^{2}+c^{2}}}Distance=a2+b2+c2​∣d2​−d1​∣​

PART 8: Angle Between Line and Plane

Given a line with direction d and plane normal n:

sinθ=∣d→.n→∣∣d→∣∣n→∣sin\theta=\frac{|\overrightarrow{d}.\overrightarrow{n}|}{|\overrightarrow{d}||\overrightarrow{n}|}sinθ=∣d∣∣n∣∣d.n∣​

A. Python Example:

d = np.array([1, 1, 0])  # direction vector of line
n = np.array([0, 0, 1])  # normal vector of plane

sin_theta = abs(np.dot(d, n)) / (np.linalg.norm(d) * np.linalg.norm(n))
theta_rad = np.arcsin(sin_theta)
theta_deg = np.degrees(theta_rad)

print("Angle between line and plane (degrees):", theta_deg)

B. Output:

Angle between line and plane (degrees): 0.0

PART 9: Line of Intersection of Two Planes

If two planes intersect, the line lies in both. To find it:

  1. Take both plane equations.

  2. Solve the system symbolically.

A. Python Example:

x, y, z = symbols('x y z')

# Two planes:
eq1 = Eq(2*x + y - z, 5)
eq2 = Eq(x - y + 2*z, 3)

sol = solve([eq1, eq2], (x, y), dict=True)
print("Intersection in parametric form:")
print(sol)

B. Output:

Intersection in parametric form:
[{x: 8/3 - z/3, y: 5*z/3 - 1/3}]

Keywords

lines in space, planes in space, vector equations, parametric equations, dot product, cross product, normal vector, point-plane distance, projection onto plane, 3D geometry, vector algebra, line-plane intersection, plane equation, line direction vector, coplanar vectors, distance from point to line, shortest distance, scalar projection, geometric visualization, vector mathematics, nerd cafe

PreviousVectors and Vector OperationsNextPartial Derivatives

Last updated 1 month ago