Concept 03: Matrices as Coordinate Transformers

▶ Interactive Demo: 2D Grid Transformation Visualizer

Open the interactive demo below to drag the landing spots of basis steps î’ and ĵ’ and see the entire coordinate grid transform in real time.


1. The Real-World Problem: Field-Centric Robot Driving

In FRC autonomous and teleop driving, the driver pushes the joystick “Forward” relative to the field.

However, if the robot is currently rotated by heading angle θ:

î' (New East) ĵ' (New North)

How does the chassis controller translate the driver’s field command [v_field_x, v_field_y] into local wheel motor voltages?


2. Solving It in Code (Java & WPILib)

First-Principles Java: 2D Rotation Matrix

// Point (x, y) = (2.0, 1.0)
double px = 2.0;
double py = 1.0;
double theta = Math.toRadians(90.0); // 90 degree rotation

// 2x2 Rotation Matrix Transformation:
// [ x_new ] = [ cos -sin ] [ px ]
// [ y_new ]   [ sin  cos ] [ py ]
double newX = Math.cos(theta) * px - Math.sin(theta) * py; // 0*2 - 1*1 = -1.0
double newY = Math.sin(theta) * px + Math.cos(theta) * py; // 1*2 + 0*1 =  2.0

System.out.printf("Rotated Vector: (%.2f, %.2f)%n", newX, newY);

Production WPILib Equivalent

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;

Translation2d point = new Translation2d(2.0, 1.0);
Translation2d rotated = point.rotateBy(Rotation2d.fromDegrees(90.0));
// Output: (-1.0, 2.0)

3. Bridge to Machine Learning: Dense Neural Layers

In deep neural networks (like ChatGPT or image classifiers):


4. Review Checkpoints

Checkpoint 1

Suppose matrix A has columns [2, 0] and [0, 3]. What is the result of A · [1, 1]?

Solution: [ 2(1) + 0(1), 0(1) + 3(1) ] = [2, 3]. The horizontal dimension was scaled by 2, and the vertical by 3.


Checkpoint 2

What matrix leaves every vector completely unchanged?

Solution: The Identity Matrix I: [ [1, 0], [0, 1] ]. Where î lands at [1, 0] and ĵ lands at [0, 1].


← Concept 09: Dot Products & Projections
Module 3 Overview
Concept 11: Determinants & Inverses →