Geometry Python

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

**Exploring Geometry Through Linear Algebra: A Python Perspective**

### Abstract
Linear algebra provides a robust framework for understanding geometric transformations,
vector spaces, and multidimensional relationships. This paper explores fundamental geometric
concepts, such as lines, planes, and transformations, through the lens of linear algebra. Python
code examples are included to clarify and visualize these concepts.

---

### 1. Introduction

Linear algebra is a cornerstone of modern mathematics with applications ranging from physics
to computer graphics. By bridging the gap between abstract theory and practical computation,
Python o ers an accessible platform to explore these concepts interactively.

---

### 2. Vectors and Their Geometric Interpretation

A vector can be thought of as a directed line segment in space. In mathematical terms, it is a


point in a vector space that has both magnitude and direction.

#### 2.1 Python Implementation


```python
import numpy as np
import matplotlib.pyplot as plt

def plot_vector(v, origin=[0, 0], color='r'):


plt.quiver(*origin, *v, angles='xy', scale_units='xy', scale=1, color=color)

# Example vectors
v1 = [2, 3]
v2 = [-1, 2]

# Plot vectors
plt. gure( gsize=(6, 6))
plot_vector(v1, color='b')
plot_vector(v2, color='g')
plt.xlim(-3, 3)
plt.ylim(-3, 3)
plt.grid()
plt.axhline(0, color='black',linewidth=0.5)
plt.axvline(0, color='black',linewidth=0.5)
plt.show()
```
The above example demonstrates two 2D vectors, which can be visualized on a Cartesian
plane. The direction and length of each vector illustrate its geometric properties.

---

### 3. Linear Transformations


fi
ff
fi
Linear transformations are functions that map vectors from one space to another while
preserving vector addition and scalar multiplication.

#### 3.1 Matrix Representation


Any linear transformation can be represented as a matrix. For example, rotation and scaling
transformations in 2D can be described as:

\[
\text{Rotation: } T(\mathbf{x}) = \begin{bmatrix}
\cos(\theta) & -\sin(\theta) \\
\sin(\theta) & \cos(\theta)
\end{bmatrix}\mathbf{x}
\]

\[
\text{Scaling: } T(\mathbf{x}) = \begin{bmatrix}
s & 0 \\
0&s
\end{bmatrix}\mathbf{x}
\]

#### 3.2 Python Implementation


```python
def rotation_matrix(theta):
return np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])

def scaling_matrix(s):
return np.array([
[s, 0],
[0, s]
])

# Example
theta = np.pi / 4 # 45-degree rotation
scale = 2 # Scaling factor

vector = np.array([1, 0])


rotated_vector = rotation_matrix(theta).dot(vector)
scaled_vector = scaling_matrix(scale).dot(vector)

print("Original vector:", vector)


print("Rotated vector:", rotated_vector)
print("Scaled vector:", scaled_vector)
```

---

### 4. Lines and Planes

#### 4.1 Line Representation


A line in 2D can be represented parametrically as:
\[
\mathbf{r}(t) = \mathbf{r}_0 + t\mathbf{v}
\]
where \(\mathbf{r}_0\) is a point on the line and \(\mathbf{v}\) is its direction vector.

#### 4.2 Plane Representation


In 3D, a plane can be represented as:
\[
\mathbf{n} \cdot (\mathbf{r} - \mathbf{r}_0) = 0
\]
where \(\mathbf{n}\) is the normal vector to the plane.

#### 4.3 Python Visualization


```python
from mpl_toolkits.mplot3d import Axes3D

# Plane parameters
point = np.array([1, 1, 1]) # A point on the plane
normal = np.array([1, -2, 1])

# Grid and plane


d = -point.dot(normal)
x, y = np.meshgrid(range(-5, 5), range(-5, 5))
z = (-normal[0] * x - normal[1] * y - d) / normal[2]

# Plot
g = plt. gure( gsize=(8, 8))
ax = g.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, alpha=0.5, color='blue')
ax.quiver(*point, *normal, color='r', length=2)
plt.show()
```
This code visualizes a 3D plane along with its normal vector.

---

### 5. Eigenvalues and Eigenvectors

Eigenvalues and eigenvectors provide insight into the properties of a transformation matrix.
They reveal invariant directions and scaling factors.

#### 5.1 Python Example


```python
matrix = np.array([[2, 1],
[1, 2]])

# Compute eigenvalues and eigenvectors


eigenvalues, eigenvectors = np.linalg.eig(matrix)
print("Eigenvalues:", eigenvalues)
print("Eigenvectors:")
print(eigenvectors)
```
---
fi
fi
fi
fi
### 6. Conclusion

Linear algebra provides powerful tools to analyze and manipulate geometric objects. Python
serves as an excellent medium to bridge theoretical concepts and practical implementation,
enhancing understanding through visualization and computation.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy