Chip Bell
\[ (x, y) \]
\[ (r, \theta) \]
\[ r = \sqrt{x^2 + y^2} \]
\[ \theta = \tan^{-1}{\frac{y}{x}} \]
\[ x = r\cos{\theta} \]
\[ y = r\sin{\theta} \]
\[ (x_1, y_1) + (x_2, y_2) = (x_1 + x_2, y_1 + y_2) \]
\[ (x_1, y_1) \cdot (x_2, y_2) = x_1 x_2 + y_1 y_2 \]
\[ (x_1, y_1) \times (x_2, y_2) = x_1y_2 - y_1x_2 \]
Given an angle $\theta$ \[ R(v, \theta) = (v_x\cos{\theta} + v_y\sin{\theta}, v_x\sin{\theta} + v_y\cos{\theta}) \]
class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
def add(self, other):
return Vector(self.x + other.x, self.y + other.y)
def negate(self):
return Vector(-self.x, -self.y)
def subtract(self, other):
return self.add(other.negate())
def dot(self, other):
return self.x * other.x + self.y * other.y
def magnitude(self):
return (self.dot(self)) ** 0.5
def cross(self, other):
return self.x * other.y - self.y * other.x
def __repr__(self):
return "{0},{1}".format(self.x, self.y)
v = Vector(1, 0)
w = Vector(0, 1)
print(v.dot(w))
print(v.cross(w))
print(v.add(w))
print(v.negate())
print(v.add(w).magnitude())
public class Vector {
protected double x;
protected double y;
public Vector(double x, double y) {
this.x = x;
this.y = y;
}
public Vector add(Vector other) {
return new Vector(this.x + other.x, this.y + other.y);
}
public Vector negate() {
return new Vector(-this.x, -this.y);
}
public Vector subtract(Vector other) {
return this.add(other.negate());
}
public double dot(Vector other) {
return this.x * other.x + this.y * other.y;
}
public double magnitude() {
return Math.sqrt(this.dot(this));
}
public double cross(Vector other) {
return this.x * other.y - this.y * other.x;
}
public String toString() {
return "" + this.x + "," + this.y;
}
public static void main(String[] args) {
Vector v = new Vector(1, 0);
Vector w = new Vector(0, 1);
System.out.println(v.dot(w));
System.out.println(v.cross(w));
System.out.println(v.add(w));
System.out.println(v.negate());
System.out.println(v.add(w).magnitude());
}
}
\[ || v || = \sqrt{v \cdot v } \]
It's the magnitude of the difference \[ || w - v || = \sqrt{ (w - v) \cdot (w - v) } \]
\[ \theta = \cos^{-1} \frac{a \cdot b }{ |a| |b| } \]
\[ |v \times w| \]
Note that you can divide in two to get the area of a triangle!
We can extend the area notion with the cross product to get the area of a polygon
Given a polygon with $n$ points $(x_0, y_0), (x_1, y_1), ..., (x_{n-1}, y_{n-1})$, we can use the Shoelace formula to calculate area: \[ A = \frac{1}{2} \sum_{i=0}^{n-1} p_i \times p_{i+1} \]
Finds the smallest convex polygon that contains a set of points
Given two line segments: \[ L_1(t) = p_1 + d_1t, 0 \le t \le 1 \] and \[ L_2(t) = p_2 + d_2t, 0 \le t \le 1 \]
We can find where the intersect by clever usage of the dot product and cross product. Figure it out yourself!