<style> .reveal-up, .reveal-left, .reveal-right, .reveal-stagger > * { opacity: 1 !important; transform: none !important; } </style>
  1. Learn
  2. BIM Math
  3. Vectors
All lessons in this course

Lesson 7 of 44 12 minBeginner

Adding, subtracting and scaling vectors

Add vectors head to tail, subtract them to get relative positions, and scale them to stretch or flip. Then use all three to route a pipe, lay out a column grid and set out a stair.

Vectors have just three basic operations, and all three work component by component: do the same thing to the X parts, the Y parts and the Z parts. That is all the arithmetic you need for most of this course.

OperationRulePicture
a + b(a.x + b.x, a.y + b.y, a.z + b.z)walk along a, then along b
a − b(a.x − b.x, a.y − b.y, a.z − b.z)the step from b’s tip to a’s tip
k × a(k·a.x, k·a.y, k·a.z)stretch by k; a negative k also flips it
Interactive

Adding, subtracting and scaling

Drag the tips of a and b (or focus a tip and use the arrow keys).

a + bab
a⟨3, 1⟩
b⟨1, 3⟩
a + b⟨3 + 1, 1 + 3⟩
= ⟨4, 4⟩
length5.66
Head to tail: walk along a, then along b, and you end at ⟨4, 4⟩. The other way round (b, then a) ends at the same place, so a + b = b + a. Components simply add.

Adding: chaining steps

A pipe run is a chain of straight runs. Each run is a vector, and the pipe’s end is its start plus every run added up. The order does not matter for where you end up (a + b = b + a), which the widget’s parallelogram shows: both routes round it meet at the same corner.

PipeRun.cs
using V3 = (double X, double Y, double Z); static V3 Add(V3 a, V3 b) => (a.X + b.X, a.Y + b.Y, a.Z + b.Z); V3[] runs = { (3, 0, 0), (0, 2, 0), (0, 0, 1.5), (-1, 0, 0) }; V3 total = (0, 0, 0);foreach (V3 run in runs) total = Add(total, run); V3 start = (10, 4, 2.5);Console.WriteLine($"Total displacement: {total}");Console.WriteLine($"Pipe ends at: {Add(start, total)}");
Output
Total displacement: (2, 2, 1.5)
Pipe ends at: (12, 6, 4)

Subtracting: where is it relative to me?

Subtraction answers “where is B as seen from A?”. Setting-out drawings are full of these: a column’s offset from a grid intersection, a sleeve’s position relative to a slab corner, a fixture’s position relative to a room origin.

Offset.cs
using V2 = (double X, double Y); V2 gridC3 = (12, 6);V2 column = (12.5, 7.25); V2 offset = (column.X - gridC3.X, column.Y - gridC3.Y);Console.WriteLine($"Column is {offset} from grid C/3");
Output
Column is (0.5, 1.25) from grid C/3

Scaling: repeats and arrays

Scaling a vector by a whole number repeats a step. An “array” command in a BIM tool is exactly this: the i-th copy sits at start + i × spacing. A two-way grid uses two spacing vectors, one per direction.

ColumnGrid.cs
using V2 = (double X, double Y); static V2 Add(V2 a, V2 b) => (a.X + b.X, a.Y + b.Y);static V2 Scale(V2 v, double k) => (v.X * k, v.Y * k); V2 origin = (0, 0);V2 along = (7.5, 0);      // bay spacing in XV2 across = (0, 6);       // bay spacing in Y for (int j = 0; j < 2; j++){    var row = new List<string>();    for (int i = 0; i < 3; i++)        row.Add(Add(origin, Add(Scale(along, i), Scale(across, j))).ToString());    Console.WriteLine(string.Join("  ", row));}
Output
(0, 0)  (7.5, 0)  (15, 0)
(0, 6)  (7.5, 6)  (15, 6)

The rules you can rely on

  • Order does not matter for adding: a + b = b + a, and (a + b) + c = a + (b + c).
  • Subtracting is adding the opposite: a − b = a + (−1)b. But a − b = −(b − a), so order matters here.
  • Scaling spreads over adding: k(a + b) = ka + kb. Scaling everything about the origin keeps every shape the same, just bigger or smaller.
  • The zero vector (0, 0, 0) is “no step”. It is the only vector with no direction, and it will need special care when you normalise.
Quick check

a = (2, 1) and b = (−1, 3). What is a + b?

Quick check

What does multiplying a vector by −0.5 do?

Practice

A straight stair starts at (2, 5, 0). Each of its 12 risers moves the walking line by (0.28, 0, 0.175): 280 mm forward and 175 mm up. Print the position of the top step with three decimals, and the total going and rise with two.

Show a hint

The top is start + 12 × step. Format each component with :F3.

Show the solution
Solution.cs
using V3 = (double X, double Y, double Z); static V3 Add(V3 a, V3 b) => (a.X + b.X, a.Y + b.Y, a.Z + b.Z);static V3 Scale(V3 v, double k) => (v.X * k, v.Y * k, v.Z * k); V3 bottom = (2, 5, 0);V3 step = (0.28, 0, 0.175);V3 top = Add(bottom, Scale(step, 12)); Console.WriteLine($"Top: ({top.X:F3}, {top.Y:F3}, {top.Z:F3})");Console.WriteLine($"Going: {12 * step.X:F2} m, rise: {12 * step.Z:F2} m");
Output
Top: (5.360, 5.000, 2.100)
Going: 3.36 m, rise: 2.10 m

Remember

  • Add, subtract and scale vectors component by component.
  • a + b chains two steps (head to tail); the order does not change where you end up.
  • B − A is the position of B relative to A: offsets, setting-out dimensions, local positions.
  • k × v stretches v by k; a negative k also reverses it. An array is start + i × spacing.
  • Writing positions as start + combinations of vectors keeps code working for rotated layouts too.
0 of 44 lessons completed