-
-
Notifications
You must be signed in to change notification settings - Fork 4
A.05 Analytic Geometry
Analytic geometry is the study of geometry using a coordinate system. As explained in appendix 01, we can represent vectors both geometrically and numerically. In analytic geometry we can use vectors in equations to numerically define geometries as set of points in a Cartesian coordinate system.
This also allows to numerically solve geometric problems such as measuring distances, calculating intersections and projections, and so on.
In this tutorial we will only scratch the surface to explain what we need to build the graphic applications presented in upcoming tutorials. However, additional information will be provided in later appendices. Also, more details can be found in the references listed at the end of this tutorial.
From appendix 01, we know that points and directions can be represented by vectors.

Lines can be described by a point
where

If we restrict the parameter
We need two points
Restricting

To measure the distance

Indeed, from trigonometry, and considering the figure above, we have that
Given a point
where the parameters
Indeed, all points of a parallelogram can be specified as the sum of the scaled sides applied to a point, as shown in the figure below.

If we restrict
Most of the time, to define a triangle we will use three points
where
In this case we call

Barycentric coordinates allow to specify a generic point
A plane can be specified by a point

As you can verify in the image above, a generic point
This is called equation of the plane because the set of points satisfying this equation represents the plane. The equation of the plane can also be written as follows
where
If
which is the well-know algebraic formula used to specify a plane in a 3D Cartesian coordinate system. Observe that here
Often we will use the vector

In general, we have a negative distance between a point and a plane if the point is behind the plane (that is, the point is in the negative\lower half-space). Indeed, the distance
which makes sense since this distance is calculated subtracting the length of the projection of

Observe that in the Cartesian systems c and d of the image above both
Therefore, if
-
If
$\mathbf{n}\cdot (\mathbf{p}-\mathbf{p} _0)=\mathbf{n}\cdot \mathbf{p}+d>0$ , then$\mathbf{p}$ is in front of the plane. -
If
$\mathbf{n}\cdot (\mathbf{p}-\mathbf{p} _0)=\mathbf{n}\cdot \mathbf{p}+d<0$ , then$\mathbf{p}$ is behind the plane. -
If
$\mathbf{n}\cdot (\mathbf{p}-\mathbf{p} _0)=\mathbf{n}\cdot \mathbf{p}+d=0$ , then$\mathbf{p}$ lies in the plane.
If we have a plane
To check if a line, a ray, or a line segment intersects a plane we can proceed as follows.
Given a line
If
Directions are free vectors (that is, it doesn't matter where we apply them). However, often to perform calculations on directions it can be useful to apply them to a common point. The figure below shows that to calculate the reflection

Observe that the normal
To reflect points with respect to a plane, we need a point on the plane in addition to its normal (that is, we need the vector

Observe that the reflection
As you can see, the reflection of directions is very similar to the reflection of points (especially if you look at the red expression above). And indeed, we can handle both these cases in the same way with the help of the following matrix of reflection with respect to a plane
Multiplying a point
In a similar way, multiplying a direction
Therefore, the matrix
A point

In this case, we have all the necessary information to build the equation of the plane
On the other hand, a point

In this case, the direction of projection is
Fortunately, we can still handle both these cases in the same way with the help of the following matrix of projection onto a plane
Multiplying a point
Computing the i-th component of
Therefore, we have that
As you can see,
so that, considering
Multiplying a vertex
$\mathbf{v}$ by$\mathbf{WS}$ (the composition between world matrix and$\mathbf{S}$ ) we get$\mathbf{s}'$ , the projection of$\mathbf{v}$ in world coordinates. It does not matter if we also multiply$\mathbf{s}'$ by$\mathbf{V}$ and\or$\mathbf{P}$ (the view and perspective projection matrices, respectively). Indeed, it ends up being a simple matrix composition where we add transformations without affecting the effect of each transformation (see appendix 03). In other word, the perspective division will take into account the term$(\mathbf{n}\cdot\mathbf{l})$ , and the terms of any other possible projections as well, because the w-component in homogeneous clip space will contain all of them.
However, we need to solve a problem: when we use the perspective division to calculate the projection of a vertex onto a plane (in addition to its perspective projection onto the projection window), the vertex could be incorrectly clipped by the rasterizer. Indeed, as explained in appendix 04, clipping is performed in homogeneous clip space, where if the w-coordinate is negative, the related vertex is considered outside the visible region, and discarded by the clipping algorithm.
Unfortunately, in this case we have that the w-coordinate contains the cosine between two vectors
$(\mathbf{n}\cdot\mathbf{l})$ , so that we can often get a negative value, as illustrated in the following image.
To solve this problem we can simply reverse the direction of projection
$\mathbf{l}$ when it forms an angle greater than$90°$ with$\mathbf{n}$ . That's not a big problem because the equation of the line$\mathbf{r}(t)$ is still the same, as well as the point of intersection. However, we will get a different solution$t_s$ for the parameter$t$ in equation$(1)$ to take into account the change of direction. Substituting$t_s$ into the equation of the line, still returns the point of intersection$\mathbf{s}$ .
On the other hand, multiplying a point
Computing the i-th component of
Therefore, we have that
As you can see,
This means that after the perspective division we get
Therefore, we just showed we can handle both cases (projection onto a plane along a direction and with respect to a point) with the help of the matrix
A general system of
where
We can also write it in matrix form as follows
where
If
Below is a practical demonstration showing the validity of this formula.
Suppose we have a system of 3 linear equations with 3 unknowns
Assuming the matrix
Therefore, the first unknown
By similar calculations we can compute the other two unknowns (
[1] Practical Linear Algebra: A Geometry Toolbox (Farin, Hansford)
[2] Introduction to 3D Game Programming with DirectX 12 (Luna)
[3] Real-Time Rendering (Haines, Möller, Hoffman)
[4] Jim Blinn's Corner: A Trip Down the Graphics Pipeline (Blinn)
If you found the content of this tutorial somewhat useful or interesting, please consider supporting this project by clicking on the Sponsor button. Whether a small tip, a one time donation, or a recurring payment, it's all welcome! Thank you!

