# CAGD/Primitives

## Overview[edit | edit source]

Simple shapes, like those used in Euclidean geometry, can be represented in either 2D or 3D space. These primitives form the basis for CAGD as well for computer graphics. We will review vectors and lines, since we will be dealing with them a lot.

Since an understanding of these concepts is needed to fully understand CAGD, we will review them quickly. There are some techniques that will be presented here that we will use often in later sections. Whether these topics relate to 2D or 3D space will not be explicitly stated, however most topics do extend from 2D into 3D.

## Definitions of Equations[edit | edit source]

This will serve as a reference for terms that we will use often in the discussion of CAGD.

**Parametric equations**: a set of equations that rely on a common independent variable. Most often, we see equations of the type:- , where t is the independent variable.

**Implicit equation**: an equation that takes the form of a function of some variables equaling zero:**Explicit equation**: a special case of parametric and implicit equations:

Although all types are seen in mathematical courses, explicit is the one most often seen and dealt with. Although explicit functions are useful, in CAGD it is more advantageous to deal with the parametric and implicit versions of the same equations for primitives.

## Vectors[edit | edit source]

Vectors have the following properties:

- A vector is an entity with both direction and magnitude.
- Vectors can represent points. They represent them as a distance from the origin to that point. This is called an
**absolute**position vector. - Vectors can represent distance between 2 points as well. This is called a
**relative**position vector. The vector - Given 2 vectors P
_{1}=(x_{1},y_{1},z_{1}) and P_{2}=(x_{2},y_{2},z_{2}), then P_{1}+P_{2}= (x_{1}+x_{2}, y_{1}+y_{2}, z_{1}+z_{2}). - Vectors can have a negative magnitude. This is equivalent to a vector with a positive magnitude with an opposite direction to the original vector.
- The magnitude (or
**norm**) can be determined by . - A unit vector, a vector with the same direction but magnitude 1, can be found by dividing the vector by its norm: .
- For Cartesian coordinate systems, the usual unit vectors in the x, y and z directions are , respectively.

### Operations on Vectors[edit | edit source]

- Dot Product: used in computing projections of one vector onto another vector.
- , where is the angle between vectors.

- Cross Product: used in many applications, including finding an orthogonal vector to two other vectors.
- , where is the angle between vectors.

- The area of a triangle with vertices at points can be quickly solved using the cross product:
- . This can be derived from the definition of the cross product and trigonometry.

## Lines[edit | edit source]

A line is the simplest kind of curve. There are many different ways to represent them:

- Parametric form:
- Vector form: , where A
_{0}is a point on the line and A_{1}is the direction of the line. - Point-slope form:
- Explicit form:
- Implicit form:

Although these are all valid expressions for a line, the more useful forms for CAGD purposes are the implicit and parametric equations.

### Affine Parametric Equation of a Line[edit | edit source]

In CAGD we like to have representations (equations) for things in a way that is independent of coordinate systems. These are called *affine* equations. For lines, affine equations mimic the parametric representations. Since 2 points define a line, all we need to find two points are two values of t. This allows us to define . For any arbitrary value of ** t**, we can define the line as the following affine equation:

This equation holds for any value of t. However, points inside the line segment bounded by P_{0} and P_{1} are bounded by .

### Implicit Equation of a Line[edit | edit source]

A line can alternatively be described as a point and a direction. If we define a point and a normal vector , we can construct an implicit equation for the line:

- ,

where **P** is a point on that line. If the line goes through two known points, then a point P = (x,y,w) is on the line if:

This corresponds with the implicit equation .

### Distance of a Point to a Line[edit | edit source]

For this, we will start with the basic implicit form of a line:

Putting it into slope-intercept form:

Putting that into a matrix:

The vector is parallel to that line, so the vector is perpendicular. So if a vector from a point P_{0} = (x_{0},y_{0}) is :

Expanding into variables:

The absolute value of the numerator just serves to get a positive number. Often it's more useful to leave the absolute value off to know which side of the line it's on. That is called the *signed distance equation*.

### Rotation of a Point About Any Line[edit | edit source]

Rotation is a fundamental part of any computer-aided design software. It can become really complex and the standard solution can involve a combination of seven 4x4 matrices. This technique is presented as a simple way to accomplish the same task with vector algebra. For most tasks, this isn't as efficient as a computational algorithm, but it should serve to show the concept of rotation.

An axis is defined as a line passing through a specific point. We can do this with a point and a vector . If we consider a vector from point A to P:

Let point B be the point of P projected onto the line. It will be the shortest distance between P and the line. We don't know the distance from A to B, so we use our S vector:

- , where is the angle between the line and the vector S.

Since we don't know the angle offhand, we could find it by using the definition of the dot product:

- , since

In order to get the vector from A to B (which we'll call ), we use some basic vector algebra:

Now that we can go from A to B with a single vector, we now turn our attention to the points P and P' on the rotation plane. Let's let the vector be defined from point B to point P and the vector be defined from B to P'. Let's also define the vector be defined as having the magnitude of r (or the length of *u*) , but rotated 90 degrees CCW such that If we let be the angle we are rotating P, we can set up the following relationship:

This is really useful because all these vectors are ones we can easily find. The algorithm then becomes:

As stated above, this algorithm is really only intended for human use. It doesn't provide any benefit in computational speed. Graphics cards and programs use rotation matrices to achieve a similar result. Because computers usually excel at performing many iterations of relatively simple tasks, the matrix method will be usually of more benefit.