Euclidean geometry is a branch of mathematics that we use for the most part in games.
It's a mathematical system first devised by the Greek Euclid and comprises the works of numerous mathematicians
of the time explaining the rules of geometry.
His work is the basis of the mathematics we know of today.
That includes plane geometry and algebra.
Euclidean geometry and algebra were first linked by René Descartes days with the invention of coordinates
that form the basis of the Cartesian coordinate system.
This coordinate system should be fairly familiar to you as it's what we grow up learning in school whenever
we need to create a graph with X and y values.
A Cartesian coordinate defines a location of a single point according to reference axes that meet at
a location called the Origin and extend away from that point perpendicular to each other in both the
positive and negative directions.
You should be familiar with the typical setup of the mapping of such a system with the Y axis extending
upwards in a positive direction and the x axis extending to the right in a positive direction.
A point in the Cartesian space is denoted by its distance along the x axis, followed by its distance
along the Y.
The coordinate for the point is written x.
Y.
For example, a 0.3 along the x axis and four along the y axis is written three four, whereas a point
minus two along the Y and minus one along the x is minus one minus two.
The x coordinate must and always comes first, followed by the Y.
The defining property of Cartesian space is that a single coordinate only identifies a single location.
If the coordinate three four is given, it cannot ever possibly be mistaken for any other location than
the one that is three along the X and four along the Y.
Cartesian coordinates can be defined for all dimensions of space from the one dimensional number line
that has a single axis to the two dimensional system we've just looked at with the x and y axis to the
three dimensional system that adds the addition of the Z axis to any number of dimensions that are difficult
to visualize in games.
We generally are most concerned with representations in two and three dimensions that is, points stored
as Z for 2D and point stored as x, y, z for 3D.
Simple data structures to hold the necessary information to define a point would look like this.
There's a float to store each dimensional coordinate for 2D, there would be two, and for 3D there
would be three.
How many floats do you think you would need for a coordinate in four dimensional space?
That's right.
Four.
There's always a value for each dimension, although we don't work with high value dimensions in games
mathematicians do, and with each increase in dimension, it just means you need another value in your
coordinate.
Before we get started with some hands on practice with points, we first need to understand the nature
of the space we will be working in.
Basically, we can think of space as a large rectangular prism with X, Y and z dimensions like this.
Of course, this is three dimensional space, the same that we ourselves live in for 2D space.
We ignore the Z axis and work on the front plane of this prism.
When space and computer graphics is represented by a cube or rectangular prism, it is called orthographic.
Another type of space representation you'll be familiar with is called perspective.
This warps space into a pyramid shape with the top cut off or what is also called a first stem.
The shape of space impacts significantly on the way we deal with it mathematically.
But we will leave these details for later in the course and begin first by using a simple orthographic
space to explore points.
We're going to begin our exploration of the Cartesian plane in unity so you can kind of get your hands
dirty with it.
Now, for this course, we're using Unity 2021.
Now I'm using 2020 1.2. 16.
If you use a slightly different version, it should be okay.
I do recommend that you use the same version that I am.
But most of this code, and that isn't specific to unity, it's what the interface that looks like is
going to be an issue for you down the track if things change dramatically.
Okay.
So we're going to start with creating a new project and we're going to make a 2D project.
So we want to go into unity.
We're going to go file and new project.
Now, when the new project window pops up, we want to select 2D.
And you want to name your project.
Well, I guess it doesn't really matter what you call it, but I'm going to call it points to D like
that and then click on the create button.
Now, when this opens up, it's going to give you a 2D view.
All right.
So here we are in our 2D view.
Now we're going to work with the coordinates within this window that you can see here.
First of all, what I'd like you to do, if we go over to the main camera, we're going to ensure that
it's set to orthographic, which it will be because we selected a 2D project.
Okay, now I want you to change the size that's just under here to 100 like that.
Now, to find where that window was again, you might just want to zoom out until you can see that part
around that border.
And I'm just going to grab my game view so that we can see what's going on over here.
And I'll set it up to 16 by nine as it's resolution.
Then we'll just move this around a little bit so we can see it there.
And the other thing I'll do, you don't have to do this, but I'm going to make the background of my
camera black so that you can see it as I'm recording what I'm doing on there.
So you want to set the camera to solid color in the clear flags and the color to black like that?
If you want to follow on with me into our scene, we're going to add a circle.
So in the hierarchy, right click to the object sprites and then you want to click circle, which is
kind of off the screen there for you.
If I can bring it over for you, circle like that.
Now you're going to get a very tiny little dot in the middle.
We're going to resize that so it's more visible.
Select the circle and the scale.
We want it to be ten in the X, ten in the Y.
So we've got the X and the Y values.
It doesn't matter about the Z.
The Z is going in and out of the screen, so you don't resize it in the Z.
It's not going to make any difference.
And to position that sphere right in the center of our plane or coordinate system, we put zero zero.
So that's the default setting that you're going to get your Cartesian plane set to in this orthographic
view with a size of 100.
Now, if you like me and you probably are, you went to school and you learnt some simple maths and
you did graphing and we did a Cartesian plane which had an x and y axis system in it.
This has an x and y axis system in it where we've got the y axis going up and down the screen and the
x axis going back and forth between the left and the right.
Now, if we move the circle using the Y value over here and grab my transform, I've lost, okay?
And then just drag it around like this.
You can see that we're actually moving up and down in the Y direction.
And so if we go this way and we go up in the positive Y direction, then we get positive numbers going
up this way.
So we know that the positive y axis is up the x axis.
The positive is going to go over to the right, which is what you would expect.
Let me set this back to zero zero.
So that means that this direction is going to be negative in the X and this direction is going to be
negative in the Y.
But that's not always the case in games because the camera moves around and therefore the axis system
can be in any particular direction.
So the y axis for the positive y could be going down the screen and the x axis could be positive in
the other direction that it is.
So the left direction.
But the thing to remember is that those two axes, they always stay at 90 degrees to each other.
And when you add in the Z axis as well, you end up with an orthogonal system.
It's called where each of those axes is all at 90 degrees to each other, and they are always at 90
degrees to each other.
Why is that important?
Well, as you'll see when we start looking at more maths and that we actually depend on those axes of
the Cartesian plane being at 90 degrees with each other.
All right.
So before we finish up with this lecture, we're going to just investigate the size of this space.
So the circle here, if I move it up like this towards the top of the screen, eventually it's going
to hit the top of the screen.
We've set this camera at an orthographic size of 100.
So what do you think the Y position at the top here is?
Well, yes.
Okay.
It's not rocket science.
It is 100.
So if we set it to 100, you'll see that the circle is up there.
What is this value down here going to be?
Well, if it's zero in the middle, then it's going to be -100 down there.
Okay.
So we've got 100 -100 down here.
We know that we have an aspect ratio for this window of 16 to 9.
What do you think the location in the X direction is for each of these things?
Can you use some mathematics to work that out?
Okay, so this is a challenge for you.
Pause a video now, see if you can come up with that calculation.
And when I come back, I'll give you the answer.
Welcome back.
How did you go with that calculation?
If you moved the circle over to the X extremes and how to look in the transform, it might have given
you a clue as to the calculation you're after, but what it is is going to be the orthographic size,
which is 100.
So it's 100 multiplied by 16 divided by nine, which is something like 177.7 something.
So if we set our X to 178, you'll see that we end up on the extreme of the X side.
And if we put our Y to zero, we'll be back in the middle.
So this is going to be 178, which means this will be -178.
How did you go with that?
It's really important that you understand the principles of the Cartesian plane and get it, I guess,
into your imagination, what's going on in these kinds of spaces.
And this is only 2D.
When you move into 3D, it becomes way more complex, but it's really about understanding these fundamental
things because they're going to underpin everything that you do in a I.
When we come back in the next lecture, we're going to look at something else that really sits underneath
of most of the algorithms you're about to learn about, and that is vectors.
You're going to find vectors everywhere throughout this course.
And so it's a really good idea that you have a firm foundation in them.