Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Block D Math
Views: 422

Analytic geometry

Analytic geometry is the study of geometry using coordinates. This is very much what you have been doing in the previous block with the vector and matrix algebra. In the case of 2D, that would be an ordered pairs of coordinates.

Equations define subsets of the plane or volume. Let’s assume we are working on a plane. An equation would often define a curve on it. For example, a linear equation would define a line:

y+3=2x y + 3 = 2 \, x

This kind of equation is called implicit equation (we'll come back to that later).

var('x','y','z'); implicit_plot(y + 3 == 2 * x, (x, -5, 5), (y, -5, 5), axes="true", aspect_ratio=1)
(x, y, z)

A square equation will define conic section, a parabola for example.

y2+4x+2y8=0 y^{2} + 4 \, x + 2 \, y - 8 = 0

implicit_plot(y^2 + 2*y + 4*x - 8 == 0, (x, -5, 5), (y, -5, 5), axes="true", aspect_ratio=1)

More complex equations can result in more complex shapes. The principle exends to 3D.

x4+y4+z4x2y2z2=0 x^{4} + y^{4} + z^{4} - x^{2} - y^{2} - z^{2} = 0

implicit_plot3d(x^4 + y^4 + z^4 - (x^2 + y^2 + z^2), (x, -2, 2), (y, -2, 2), (z, -2, 2))
3D rendering not yet implemented

Line

Let's start by anaizying the equation of a line. The susbset of R2 R^{2} that satisfies the linear equation

Ax+By+C=0 Ax + By + C = 0

is a line. Let's plot such a line.

var('x','y','z','A','B','C') @interact def _(A=slider(-3, 3), B=slider(-3,3), C=slider(-3,3)): show(implicit_plot(A*x + B*y + C == 0, (x, -10, 10), (y, -10, 10), axes="true", aspect_ratio=1))
(x, y, z, A, B, C)
Interact: please open in CoCalc

Often we use an angle (or inclination) and intercept to describe a line. The angle is measured from the postive x-axis to the line. Inclination is the tan of the angle. The equation in this form is:

y=mx+b y = mx + b

Where m is the inclination and b the y intercept.

var('x','y','z') @interact def _(m=slider(-3, 3), b=slider(-3,3)): show(implicit_plot(y == m * x + b, (x, -10, 10), (y, -10, 10), axes="true", aspect_ratio=1));
(x, y, z)
Interact: please open in CoCalc

We can convert from one form of the equation to the other.

var('A','B','C'); show(solve(A*x + B*y + C == 0, y));
(A, B, C)
[y=Ax+CB\displaystyle y = -\frac{A x + C}{B}]

Both forms of the line equation that were given are impicit. This means every x and y that satisfy the equation are on the line. The second form lets us calculate the y value for evey x value, but using implicit equation is not the best solution for all problems. Often is easier to work with a set of parametric equtions. One for each dimension and one parameter for each degree of freedom (for ex. 1 for a curve/line, 2 for a surface). The parametric equations for a line look like this.

x=x0+at x = x_0 + at

y=y0+bt y = y_0 + bt

A parametric equation for a line is basically made out of a point on the line and a direction vector, multiplied by the parameter tt. In vector form it might be a bit more clear.

x=x0+nt \vec{x} = \vec{x}_0 + \vec{n}t

If the direction is normalized, the the tt parameter will give us the signed distance from the intial point.

var('x','y','t'); x0=[2,3]; n=[1,1]; p0=parametric_plot((x0[0]+n[0]*t, x0[1]+n[1]*t), (t, -5, 5)); p1=list_plot([x0]); show(p0+p1);
(x, y, t)

Any two non-paralel lines will instersect. Two paraler lines wll either overlap or have not intersection. Let us start off with an example.

We have two lines defined with the equations.

3y+2x6=03y+2x-6=0

5y2x10=05y-2x-10=0

To find the intersection we need to find such xx and yy the satisfy both equations. We can rewrite the system as:

{2x+3y=62x+5y=10 \begin{cases} 2x+3y=6 \\ –2x + 5y=10 \end{cases}

We can solve the system using Sage and the solve function

p=solve([3*y+2*x-6==0,5*y-2*x-10==0],x,y)
[[x == 0, y == 2]]
%md The equivalend of a line in 2D is a plane in 3D. A plane can de defined by a point on the plane and normal. The equation could be written to take all the poistions $\vec{r}$ such that the vector drawn from $\vec{r}_0$ to $\vec{r}$ is perpendicular to $\vec{n}$. $ \vec{n}\cdot(\vec{r}-\vec{r}_0)=0 $ The general equation of a plane in 3D can be derived from that formula. $ Ax+By+Cz+d=0 $ Naturally, we can extend the intersection problem to 3D. For example, let's try to find the intersection of three planes, described by the folowing system. $ \begin{cases} 3x+2y+1z=10 \\ 2x+1y+3z=13 \\ 1x+3y+2z=13 \end{cases} $ We can also write this in a matrix form $ \boldsymbol{A} \cdot \vec{x} = \boldsymbol{b} $ $ \begin{bmatrix} 3 & 2 & 1 \\ 2 & 1 & 3 \\ 1 & 3 & 2 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} 10 \\ 13 \\ 13 \end{bmatrix} $ If we multiply the system with $ \boldsymbol{A}^{-1} $ we get the solution of the system. $ \vec{x} = \boldsymbol{A}^{-1} \cdot \boldsymbol{b} $ This is why the methods for finding an inverse of a matrix and finding solutions for systems of linear equations are tightly connected. We will use sage here to solve the system in it's matrix form and appying the inverse. And then repeat the same using the Gaussian elliminations method (which probably takes another full workshop to practise, but do check the Wikipedia article in meantime). Gaussian elliminations starts with creating an augumented matrix, by appending the $b$ vector. We apply **elementary row operations** untill we get a identity matrix on the left side. The alowed ERO are: - Swapping two rows. - Multiplying a row by a non-zero number. - Adding a multiple of one row to another row.

The equivalend of a line in 2D is a plane in 3D. A plane can de defined by a point on the plane and normal. The equation could be written to take all the poistions r\vec{r} such that the vector drawn from r0\vec{r}_0 to r\vec{r} is perpendicular to n\vec{n}.

n(rr0)=0 \vec{n}\cdot(\vec{r}-\vec{r}_0)=0

The general equation of a plane in 3D can be derived from that formula.

Ax+By+Cz+d=0 Ax+By+Cz+d=0

Naturally, we can extend the intersection problem to 3D. For example, let's try to find the intersection of three planes, described by the folowing system.

{3x+2y+1z=102x+1y+3z=131x+3y+2z=13 \begin{cases} 3x+2y+1z=10 \\ 2x+1y+3z=13 \\ 1x+3y+2z=13 \end{cases}

We can also write this in a matrix form

Ax=b \boldsymbol{A} \cdot \vec{x} = \boldsymbol{b}

[321213132][xyz]=[101313] \begin{bmatrix} 3 & 2 & 1 \\ 2 & 1 & 3 \\ 1 & 3 & 2 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} 10 \\ 13 \\ 13 \end{bmatrix}

If we multiply the system with A1 \boldsymbol{A}^{-1} we get the solution of the system.

x=A1b \vec{x} = \boldsymbol{A}^{-1} \cdot \boldsymbol{b}

This is why the methods for finding an inverse of a matrix and finding solutions for systems of linear equations are tightly connected. We will use sage here to solve the system in it's matrix form and appying the inverse. And then repeat the same using the Gaussian elliminations method (which probably takes another full workshop to practise, but do check the Wikipedia article in meantime).

Gaussian elliminations starts with creating an augumented matrix, by appending the bb vector. We apply elementary row operations untill we get a identity matrix on the left side. The alowed ERO are:

  • Swapping two rows.

  • Multiplying a row by a non-zero number.

  • Adding a multiple of one row to another row.

# Define the vars A = Matrix(QQ,[[3, 2, 1], [2, 1, 3], [1, 3, 2]]); b = vector([10, 13, 13]); # Use the sage built-in solver print(A.solve_right(b)); # Use the inverse Ai=A.inverse(); p=Ai*b; print(p); print(A*p);
(1, 2, 3) (1, 2, 3) (10, 13, 13)
# Create matrix A=Matrix(QQ,[[3, 2, 1, 10], [2, 1, 3, 13], [1, 3, 2, 13]]); show(A); A.add_multiple_of_row(1, 0, -2/3) A.add_multiple_of_row(2, 0, -1/3) show(A); A.set_row_to_multiple_of_row(1, 1, -3) A.set_row_to_multiple_of_row(2, 2, 3) show(A); A.add_multiple_of_row(0, 1, -2) A.add_multiple_of_row(2, 1, -7) show(A); A.set_row_to_multiple_of_row(0, 0, 1/3) A.set_row_to_multiple_of_row(2, 2, 1/54) show(A); A.add_multiple_of_row(0, 2, -5) A.add_multiple_of_row(1, 2, 7) show(A);
(321102131313213)\displaystyle \left(\begin{array}{rrrr} 3 & 2 & 1 & 10 \\ 2 & 1 & 3 & 13 \\ 1 & 3 & 2 & 13 \end{array}\right)
(321100137319307353293)\displaystyle \left(\begin{array}{rrrr} 3 & 2 & 1 & 10 \\ 0 & -\frac{1}{3} & \frac{7}{3} & \frac{19}{3} \\ 0 & \frac{7}{3} & \frac{5}{3} & \frac{29}{3} \end{array}\right)
(321100171907529)\displaystyle \left(\begin{array}{rrrr} 3 & 2 & 1 & 10 \\ 0 & 1 & -7 & -19 \\ 0 & 7 & 5 & 29 \end{array}\right)
(301548017190054162)\displaystyle \left(\begin{array}{rrrr} 3 & 0 & 15 & 48 \\ 0 & 1 & -7 & -19 \\ 0 & 0 & 54 & 162 \end{array}\right)
(10516017190013)\displaystyle \left(\begin{array}{rrrr} 1 & 0 & 5 & 16 \\ 0 & 1 & -7 & -19 \\ 0 & 0 & 1 & 3 \end{array}\right)
(100101020013)\displaystyle \left(\begin{array}{rrrr} 1 & 0 & 0 & 1 \\ 0 & 1 & 0 & 2 \\ 0 & 0 & 1 & 3 \end{array}\right)
%md ### Circle A circle can be defined by all the points that are at equal distnace from it's center. Let's first assume that the center is at $[0,0]$ and has a radius $r$. The equation is: $ x^2+y^2=r^2 $ If we assume that center is at $C[h,k]$, we simply translate the equation: $ (x-h)^2+(y-k)^2=r^2 $ The general equation of a circle is a square equation with form: $ x^2 + y^2 + ax + by + c = 0 $ With center at $ C=(−a/2, −b/2) $ and radius $ r = \frac{1}{2} \sqrt{a^2+b^2-4c} $ Lastly a circle can be defined with parameric equations: $ x=h + r \cdot cos(t) $ $ y=k + r \cdot sin(t) $

Circle

A circle can be defined by all the points that are at equal distnace from it's center. Let's first assume that the center is at [0,0][0,0] and has a radius rr. The equation is:

x2+y2=r2 x^2+y^2=r^2

If we assume that center is at C[h,k]C[h,k], we simply translate the equation:

(xh)2+(yk)2=r2 (x-h)^2+(y-k)^2=r^2

The general equation of a circle is a square equation with form:

x2+y2+ax+by+c=0 x^2 + y^2 + ax + by + c = 0

With center at C=(a/2,b/2) C=(−a/2, −b/2) and radius r=12a2+b24c r = \frac{1}{2} \sqrt{a^2+b^2-4c}

Lastly a circle can be defined with parameric equations:

x=h+rcos(t) x=h + r \cdot cos(t)

y=k+rsin(t) y=k + r \cdot sin(t)

var('x','y','t','u','v'); line_eq(x,y)=x-y+1.0==0.0; circle_eq(x,y)=(x-1)^2+(y-1)^2==2^2; p0=implicit_plot(line_eq, (x,-5, 5), (y, -5, 5), axes="true", aspect_ratio=1); p1=implicit_plot(circle_eq, (x,-5, 5), (y, -5, 5), axes="true", aspect_ratio=1); show(p0+p1); # # Solution using Sage's solver for everything solve([line_eq, circle_eq], x, y) # # Solution step by step # 1. Solve for y from the line equation, extract the solution with some Sage specific magic and confirm it sol(x) = solve(line_eq, y)[0].rhs(); print(sol(x)); # 3. Substitute in the circle equation circle_eq2(x)=circle_eq(x,sol); print(circle_eq2(x)); # 4. Solve that equation for x now xsolutions = solve(circle_eq2(x),x); x1 = xsolutions[0].rhs(); x2 = xsolutions[1].rhs(); print(x1, sol(x1)); print(x2, sol(x2));
(x, y, t, u, v)
[[x == -1/2*sqrt(7) + 1/2, y == -1/2*sqrt(7) + 3/2], [x == 1/2*sqrt(7) + 1/2, y == 1/2*sqrt(7) + 3/2]] x + 1 (x - 1)^2 + x^2 == 4 (-1/2*sqrt(7) + 1/2, -1/2*sqrt(7) + 3/2) (1/2*sqrt(7) + 1/2, 1/2*sqrt(7) + 3/2)
(4,1) (-3,7) (5,-2)
var('x','y','h','k','r'); circle_eq(x, y, h, k, r)=(x-h)^2+(y-k)^2==r^2; sol = solve([circle_eq(4, 1, h, k ,r),circle_eq(-3, 7, h, k ,r), circle_eq(5, -2, h, k ,r)], h, k, r); print(sol); hval=sol[1][0].rhs(); kval=sol[1][1].rhs(); rval=sol[1][2].rhs(); hval kval rval p0=implicit_plot(circle_eq(x, y, hval, kval, rval), (x,-10, 10), (y, -10, 10), axes="true", aspect_ratio=1); p1=list_plot([(4,1),(-3,7),(5,-2)]); show(p0+p1);
(x, y, h, k, r) [ [h == (-13/2), k == (-25/6), r == -1/6*sqrt(2465)*sqrt(2)], [h == (-13/2), k == (-25/6), r == 1/6*sqrt(2465)*sqrt(2)] ] -13/2 -25/6 1/6*sqrt(2465)*sqrt(2)

Ellipse

Circles, ellipses and parabolas and hyperbolas are called conic sections, as they can be derived by intersecting a cone (the mathematical endless, double sided one) and a plane. Sometimes we use the short name conics. We will only focus on the ellipse in this workshop and it's the most usefull one for graphics and collision detection.

An ellipse can be defined using it's major axis aa and minor axis bb. Let's first assume that the center is at [0,0][0,0]. The equation is:

(xa)2+(yb)2=1 (\frac{x}{a})^2+(\frac{y}{b})^2=1

If we assume that center is at C[h,k]C[h,k], we simply translate the equation:

(xha)2+(ykb)2=1 (\frac{x-h}{a})^2+(\frac{y-k}{b})^2=1

Lastly a circle can be defined with parameric equations:

x=h+acos(t) x=h + a \cdot cos(t)

y=k+bsin(t) y=k + b \cdot sin(t)

(x, y, h, k, a, b, theta, t, n)
116(2(x3)+2(y5))2+14(2(x3)2(y5))2=1\displaystyle \frac{1}{16} \, {\left(\sqrt{2} {\left(x - 3\right)} + \sqrt{2} {\left(y - 5\right)}\right)}^{2} + \frac{1}{4} \, {\left(\sqrt{2} {\left(x - 3\right)} - \sqrt{2} {\left(y - 5\right)}\right)}^{2} = 1
[[x == -2/13*sqrt(10) + 25/13, y == -4/13*sqrt(5)*sqrt(2) + 63/13], [x == 2/13*sqrt(10) + 25/13, y == 4/13*sqrt(5)*sqrt(2) + 63/13]] [ 1/2*sqrt(2) 1/2*sqrt(2) 0 -1/2*sqrt(2) 1/2*sqrt(2) 0 0 0 1]
var('x','y','h','k','a','b','theta','t','n'); ellipse_eq(x,y) = (((x-h)*cos(theta)+(y-k)*sin(theta))^2) / (a^2) + ( ((x-h)*sin(theta) - (y-k)*cos(theta))^2 ) / (b^2) == 1; show(ellipse_eq(x,y)); show(expand(ellipse_eq(x,y)))
(x, y, h, k, a, b, theta, t, n)
((hx)cos(θ)+(ky)sin(θ))2a2+((ky)cos(θ)(hx)sin(θ))2b2=1\displaystyle \frac{{\left({\left(h - x\right)} \cos\left(\theta\right) + {\left(k - y\right)} \sin\left(\theta\right)\right)}^{2}}{a^{2}} + \frac{{\left({\left(k - y\right)} \cos\left(\theta\right) - {\left(h - x\right)} \sin\left(\theta\right)\right)}^{2}}{b^{2}} = 1
h2cos(θ)2a2+k2cos(θ)2b22hxcos(θ)2a2+x2cos(θ)2a22kycos(θ)2b2+y2cos(θ)2b2+2hkcos(θ)sin(θ)a22hkcos(θ)sin(θ)b22kxcos(θ)sin(θ)a2+2kxcos(θ)sin(θ)b22hycos(θ)sin(θ)a2+2hycos(θ)sin(θ)b2+2xycos(θ)sin(θ)a22xycos(θ)sin(θ)b2+h2sin(θ)2b2+k2sin(θ)2a22hxsin(θ)2b2+x2sin(θ)2b22kysin(θ)2a2+y2sin(θ)2a2=1\displaystyle \frac{h^{2} \cos\left(\theta\right)^{2}}{a^{2}} + \frac{k^{2} \cos\left(\theta\right)^{2}}{b^{2}} - \frac{2 \, h x \cos\left(\theta\right)^{2}}{a^{2}} + \frac{x^{2} \cos\left(\theta\right)^{2}}{a^{2}} - \frac{2 \, k y \cos\left(\theta\right)^{2}}{b^{2}} + \frac{y^{2} \cos\left(\theta\right)^{2}}{b^{2}} + \frac{2 \, h k \cos\left(\theta\right) \sin\left(\theta\right)}{a^{2}} - \frac{2 \, h k \cos\left(\theta\right) \sin\left(\theta\right)}{b^{2}} - \frac{2 \, k x \cos\left(\theta\right) \sin\left(\theta\right)}{a^{2}} + \frac{2 \, k x \cos\left(\theta\right) \sin\left(\theta\right)}{b^{2}} - \frac{2 \, h y \cos\left(\theta\right) \sin\left(\theta\right)}{a^{2}} + \frac{2 \, h y \cos\left(\theta\right) \sin\left(\theta\right)}{b^{2}} + \frac{2 \, x y \cos\left(\theta\right) \sin\left(\theta\right)}{a^{2}} - \frac{2 \, x y \cos\left(\theta\right) \sin\left(\theta\right)}{b^{2}} + \frac{h^{2} \sin\left(\theta\right)^{2}}{b^{2}} + \frac{k^{2} \sin\left(\theta\right)^{2}}{a^{2}} - \frac{2 \, h x \sin\left(\theta\right)^{2}}{b^{2}} + \frac{x^{2} \sin\left(\theta\right)^{2}}{b^{2}} - \frac{2 \, k y \sin\left(\theta\right)^{2}}{a^{2}} + \frac{y^{2} \sin\left(\theta\right)^{2}}{a^{2}} = 1