4.2.8.1 - Vectors, translation and dot products (C#)
Represent vectors as lists, arrays and functions, use them for translation and scaling, and calculate dot products and angles. This C# route is incomplete: runnable support pending; code questions are written practice with no Run.
List, array and function representations
A vector is an ordered collection of entries drawn from the same field, such as the real numbers.
The vector has four real entries, so it is a 4-vector over , written as a member of . Order matters: exchanging entries usually changes the vector. A two-vector can represent a point in a plane, but a four-vector need not describe four physical directions; its entries might be four measurements.
The same vector can be viewed as a function , with domain and codomain the reals. Its mappings are , , , . The arrow means “maps to”: one value is assigned to each domain index. A dictionary directly represents these index-to-value pairs.
double[] array = { 2.0, 3.14159, -1.0, 2.718281828 };
List<double> list = new List<double> { 2.0, 3.14159, -1.0, 2.718281828 };
Dictionary<int, double> function = new Dictionary<int, double>
{
{ 0, 2.0 }, { 1, 3.14159 }, { 2, -1.0 }, { 3, 2.718281828 }
};
Import System.Collections.Generic for List and Dictionary. All three give −1.0 at index/key 2. The list is resizable and the array has fixed length; the dictionary must contain every domain index to represent this full vector. Its iteration order does not define coordinate order; the keys do. C# double approximates real numbers in finite storage; is the mathematical field, not a claim that a machine stores every real exactly.
Geometric vectors
A two-dimensional vector can be drawn as an arrow whose displacement is given by its two entries.
For , an arrow from origin (0,0) to (2,3) moves two units right and three up. Its magnitude is . An arrow from (4,1) to (6,4) has the same displacement [2,3], although its tail is elsewhere. A position vector specifically has its tail at the origin and identifies a point.
[DIAGRAM: asset_slug: vector_coordinates; description: Exact coordinate plot of u equals (2,3), v equals (4,1), their sum (6,4), and the convex point (3.5,1.5) on the segment joining u and v]

The geometric model applies to points and movement in graphics. A negative coordinate moves left or down under the chosen axes. The zero vector [0,0] has magnitude zero and no defined direction, which matters when calculating an angle later.
Addition, scaling and convex combinations
Vector arithmetic combines corresponding entries, so the vectors must have the same dimension.
Continue this lesson.
You’re previewing NovaLearn without an account. Create a free account to read the rest.
Create free account