Coordinates

This article is about coordinate systems. We have already seen coordinates in other contexts, but I want to go over them just a little more here.

We can construct a coordinate system in any number of dimensions we like. For this course, we will only touch one, two and three dimensional systems.

A one dimensional coordinate system is very simple. A simple number line can be considered a kind of coordinate system. To give a real life example, imagine a car on a straight rail. We can call the start position \(x=0\). If the car has constant velocity \(v=10\), we can ask where it will be at time \(t\). For example, at \(t=1\), the car will be at \(x=10\) and so on.

Two dimensional coordinate systems present something much more interesting though. The first thing we can do with these coordinate systems is plot them, and we can plot functions, lines and curves. We've already seen this, so here's a brief recap. Below is a graph of \(y = x^3 + 2x^2 - x + 4\)

Writing specific coordinates, we usually use the \((x, y)\) notation. We can take a single coordinate and transform it by multiplying by a number. If we have coordinate \(P = (x, y)\), then multiplying by \(a\) would be \(aP = a(x, y) = (ax, ay)\). If \(a>1\) then the coordinate will move further from the origin (the origin is \((0,0)\)), if \(a>1\) the point will be closer to the origin. If \(a=-1\), then a reflection will be seen. The graph below shows a variety of different transformations on the point \((1,1)\).

If we have two points, we can calculate the distance between them very simply. If we have point \((x_1, y_1)\) and point \((x_2, y_2)\) then the distance between them is simply

\[d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}\]

Which you may notice is actually the Pythagorean theorem in disguise.

Finally, I want to talk about circles. A circle on a two dimensional coordinate system has an equation. Maybe people think of this as a function, but that isn't strictly true. The difference is that a function gives you a particular output for a particular input value. To quickly tell if you have a function or an equation, if you can draw a vertical line on the graph which anywhere passes through two points of the line, you have a equation.

The equation of a circle is given by

\[(x-a)^2 + (y-b)^2 = r^2\]

Which is centred on \((a,b)\) and has radius \(r\).

To drum home the point that this is an equation and not a function, I made the following graph. What I have done here is checked points on the coordinate plane to see if they satisfy the condition \(x^2 + y^2 < 1\). I have presented the Rust code in the appendix for those interested.

The three dimensional case has many similarities. To find the distance between two points in three dimensional space we simply use

\[d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}\]

The equation for a sphere in three dimensional space is

\[(x-a)^2 + (y-b)^2 + (z-c)^2 = r^2\]

Many people are tempted to use cubes and cube roots when moving the equations from 2D to 3D space - that isn't how it works!


Appendix

Rust to check what colour to make a point, whether it is outside, inside or on the perimeter of the circle.


            struct Coordinates {
                pub x: Vec<f64>,
                pub y: Vec<f64>,
            }

            impl Coordinates {
                fn default() -> Coordinates {
                    return Coordinates {
                        x: vec![],
                        y: vec![],
                    };
                }

                fn new_point(&mut self, x: &f64, y: &f64) {
                    self.x.push(x.clone());
                    self.y.push(y.clone());
                }
            }

            struct CirclePoints {
                pub outside: Coordinates,
                pub inside: Coordinates,
                pub perimeter: Coordinates,
            }

            impl CirclePoints {
                fn default() -> CirclePoints {
                    return CirclePoints {
                        outside: Coordinates::default(),
                        inside: Coordinates::default(),
                        perimeter: Coordinates::default(),
                    };
                }
            }

            enum CircleCondition {
                Inside,
                Outside,
                Perimeter,
            }

            fn circle_eqaution(x: &f64, y: &f64) -> CircleCondition {
                fn equation(x: &f64, y: &f64) -> f64 {
                    return (x.powf(2_f64) + y.powf(2_f64)).sqrt();
                }
                let radius = 1.0;
                let result = equation(x, y);
                if result > radius {
                    return CircleCondition::Outside;
                } else if result == radius {
                    return CircleCondition::Perimeter;
                } else {
                    return CircleCondition::Inside;
                }
            }

            fn get_circle_points(
                circle_eqaution: &dyn Fn(&f64, &f64) -> CircleCondition,
                x_lim: (f64, f64),
                y_lim: (f64, f64),
                resolution: usize,
            ) -> CirclePoints {
                let mut coords = CirclePoints::default();
                let x_points: Vec<f64> = linspace(x_lim.0, x_lim.1, resolution).collect();
                let y_points: Vec<f64> = linspace(y_lim.0, y_lim.1, resolution).collect();

                for x in &x_points {
                    for y in &y_points {
                        match circle_eqaution(x, y) {
                            CircleCondition::Inside => coords.inside.new_point(x, y),
                            CircleCondition::Outside => coords.outside.new_point(x, y),
                            CircleCondition::Perimeter => coords.perimeter.new_point(x, y),
                        };
                    }
                }

                return coords;
            }