Coordinate geometry in the (x,y) plane


In [18]:
import numpy as np
import matplotlib.pyplot as plt

Straight Lines

Equations

Main Equation:

$y = Mx + c$

Can be re-formated though:

$ax + by + c = 0$

Can find equation of line given known point and gradient

Example:

x = 3

y = 6

M = 4

$6 = 4\times 3 + c$

$c = -6$

$y = 4x - 6$

Gradient Equation:

$M = \frac{y_2 - y_1}{x_2 - x_1}$ or $M = \frac{dy}{dx}$

Can be used to find gradient from 2 known points (and used to find equation after)

Example

$x_1 = 2$

$y_1 = -1$

$x_2 = 7$

$y_2 = -15$

$M = \frac{-15 + 1}{7 - 2}$

$M = \frac{-14}{5}$

$M = -2\frac{4}{5}$

We can also use this re-formated equation to find the full equation of the line

$(y - y_1) = M(x - x_1)$

With $x_1$ and $y_1$ and $M$ as our known variables

Example

$(y - 6) = 4(x - 3)$

$y = 4x - 6$


In [19]:
# x data
x = np.linspace(-10, 10, 2001).astype(np.float32)

# variables
x1 = 2
x2 = 7
y1 = -1
y2 = -15

# gradient function
def grad(x1, x2, y1, y2):
    return((y2-y1)/(x2-x1))

# line function
def f(y1, x1, x, M):
    c = y1 - M*x1
    return(M*x + c, c)

# get the gradient
M = grad(x1, x2, y1, y2)

# get the y values
# also get the c value to use in our plot key
y, c = f(y1, x1, x, M)

# set up plot
fig, ax = plt.subplots(figsize=(8,4))

ax.plot(x,y, label='y = %sx + %s' % (M, c))

ax.legend()
ax.grid(True)

plt.show()


Line conditions

Parallel

The gradient must be the same

Perpendicular

The gradient must be the negative reciprocal

$-M^{-1}$


In [20]:
# x data
x = np.linspace(-10, 10, 2001).astype(np.float32)

# variables
M = 3.0
c = 2.0

# line function
def f(M, x, c):
    return(M*x + c)

# parallel line function
def par_f(M, x, c):
    new_c = c-4
    return(M*x + new_c, new_c)

# perp line function
def perp_f(M, x, c):
    new_M = -np.reciprocal(M)
    return(new_M*x + c, new_M)

# get the y values
y = f(M, x, c)
par_y, par_c = par_f(M, x, c)
perp_y, perp_M = perp_f(M, x, c)

# set up plot
fig, ax = plt.subplots(figsize=(4,4))

ax.plot(x,y, label='y = %sx + %s' % (M, c))
ax.plot(x,par_y, label='y = %sx + %s' % (M, par_c))
ax.plot(x,perp_y, label='y = %sx + %s' % (perp_M, c))

ax.legend(bbox_to_anchor=(1.05, 1), loc=2)
ax.grid(True)

plt.xlim(-2, 4)
plt.ylim(-2, 4)

plt.show()


Mid points

To find mid point, find average of x and y

$P = \left(\frac{x_1+x_2}{2}, \frac{y_1+y_2}{2}\right)$

Distance between points

Use pythagoras's theorem

$D = \sqrt{(y_2 - y_1)^2 + (x_2 - x_1)^2}$

Coordinate Geometry of the Circle

Radius equation

This is the same as pythagoras's theorem

with (x,y) as point on radius with (a,b) as point at centre of circle

$(x-a)^2+(y-b)^2=r^2$

tangent: straight line which touches the circle/curve

normal: line perpendicular to tangent passing through centre of circle

Circle equation

Circles come as this equation:

$Ax^2 + Ay^2 + Bx + Cy + D = 0$

To complete the square:

$\left(\sqrt{A}x + \frac{B}{2\sqrt{A}}\right)^2 - \left(\frac{B}{2\sqrt{A}}\right)^2 + \left(\sqrt{A}y + \frac{C}{2\sqrt{A}}\right)^2 - \left(\frac{C}{2\sqrt{A}}\right)^2 = -D$

$\left(\sqrt{A}x + \frac{B}{2\sqrt{A}}\right)^2 + \left(\sqrt{A}y + \frac{C}{2\sqrt{A}}\right)^2 = \left(\frac{C}{2\sqrt{A}}\right)^2 + \left(\frac{B}{2\sqrt{A}}\right)^2 - D$

note: the right hand side should be $r^2$

Example

$x^2 + y^2 - 2x - 4y - 4 = 0$

$x^2 - 2x + y^2 - 4y = 4$

$(x - 1)^2 + (y - 2)^2 = 4 + (-2)^2 + (-1)^2$

$(x - 1)^2 + (y - 2)^2 = 3^2$

  • (-1, -2) = centre point
  • $3$ = radius

Rules

  • the angle on circumference with lines from the edges of a diameter = right angle
  • the perpendicular from the centre to a chord bisects the chord
  • the radius is perpendicular to the tangent of a given point on the circles circumference

Parametric Equations

  • defines a coordinate of a point on a curve
  • x and y expressed as:
  • $x = f(t)$
  • $y = g(t)$
  • uses t as parameter
  • can also use $\theta$ if its an angle

Useful for:

  • direction of line would indicate the direction of an object as the parameter increases
  • can tell position of object at any given point (the point is t)
  • cannot write $f(x,y,z)=0$ for 3d curve, so we need parametric equations

Circle

circles expressed as:

$x^2 + y^2 = r^2$

parametric equations:

$x = r\cos(\theta))$

$y = r\sin(\theta))$

Parabola

parabolas expressed as:

$y^2=4ax$

parametric equations:

$x=at^2$

$y=2at$

note: $t = \sqrt{\frac{x}{a}}$ so $x = x$ and $y = 2a\sqrt{\frac{x}{a}}$ so $y^2 = 4ax$

Ellipse

Ellipse expressed as:

$\displaystyle \frac{x^2}{a^2}+\displaystyle \frac{y^2}{b^2}=1$

parametric equations:

$x = a\cos(\theta)$

$y = b\sin(\theta)$

Rectangular hyperbola

Rectangular hyperbola expressed as:

$xy=c^2$

parametric equations:

$x=ct$

$\displaystyle y=\frac{c}{t}$

Conversion between Cartesian and parametric forms

Method 1

  • make t the subject in one equation
  • substitute into the other equation

Example

Parametric equations:

$x = at^2$

$y = 2at$

Cartesian equation in terms of y:

$t = \frac{y}{2}$

$x = a\left(\frac{y}{2a}\right)^2$

$x = \frac{y^2}{4a}$

Cartesian equation in terms of x:

$y^2 = 4ax$

This is the equation of a parabola

Method 2

  • when using $\theta$
  • use trigonometric identities (relationships)
  • to eliminate $\theta$

Example

Parametric equations:

$x = 3 \cos(\theta)$

$y = 4 \sin(\theta)$

Cartesian equation:

$\cos(\theta) = \frac{x}{3}$

$\sin(\theta) = \frac{y}{4}$

$\cos^2(\theta) = \left(\frac{x}{3}\right)^2$

$\sin^2(\theta) = \left(\frac{y}{4}\right)^2$

Using trig identity: $\sin^2(\theta) + \cos^2(\theta) = 1$

$\left(\frac{x}{3}\right)^2 + \left(\frac{y}{4}\right)^2 = 1$

This is the equation of an ellipse

To convert from Cartesian to parametric:

  • make t = part of x = ... or y = ...
  • substitute in

Example

$xy = c^2$

$x = \frac{c^2}{y}$

$y = \frac{c^2}{x}$

let $t = \frac{c}{y}$

$x = ct$

$y = \frac{c^2}{ct}$

$y = \frac{c}{t}$

We could have also used a different t value like $t = \frac{1}{y}$ where:

$x = c^2t$

$y = \frac{1}{t}$