The Same Two Fixed-Axis Turns Can End in Different Directions

Download and extract the reader ZIP archive (a compressed collection of files). Links labelled “reader ZIP; extract …” download this archive; after extraction, open the named file. It includes the offline article, full-size Portable Network Graphics (PNG) images, editable Scalable Vector Graphics (SVG) diagrams, complete source code, tests and worksheets.

Point a vector along the global x-axis. Turn it a quarter revolution about x, then about y. Reverse those same two turns and the final direction changes. This lesson makes the order explicit with exact integer matrices and a labelled paper triad.

A vector is a quantity represented here by three coordinate components, such as v = (1, 0, 0). A coordinate frame supplies an origin and three perpendicular unit axes. A unit vector has length one. Our global, or fixed, frame stays in the same orientation for every operation. All supplied data and drawings are constructed calculations. No machine, robot, sensor or measured orientation is involved.

Prepare the paper and offline files

Use three paper strips, a small card with a drawn arrow, a pencil, tape, a right-angle corner and a computer. The optional paper arrangement helps you predict directions; it does not measure or calibrate an orientation. The delivered model uses only Python’s standard library. Author behavior tests used CPython 3.12.14; CPython is the reference implementation of Python. Use Python 3.12 or later for the stated reproduction environment.

After downloading the ZIP archive, a compressed collection of files, extract it first and read README.txt — reader ZIP; extract README.txt. The article is stored as Hypertext Markup Language (HTML). The extracted files include the complete offline lesson. JavaScript Object Notation (JSON) is the text format for the records; its null value means no entry, not zero. Portable Network Graphics (PNG) files are full-size images, and Scalable Vector Graphics (SVG) files are their editable originals. Keep the code, assets, data and evidence folders together. No archive is nested inside itself.

Fix the axes before choosing the order

Use a right-handed frame: x points right, y points away from you along the desk, and z points upward. The right-hand rule fixes a positive rotation. Point your right thumb along the positive axis; your curled fingers indicate the positive turn. Viewed from the positive end of that axis toward the origin, it is counterclockwise. A quarter turn is 90 degrees; a negative quarter turn reverses it. A clockwise label alone is insufficient without a viewing direction.

These are active rotations: we turn the vector while continuing to express its components in the original global frame. The axes do not follow it. If an axis turns with an object, it is a moving or body axis, and the interpretation of a sequence changes. The program below implements only fixed global axes, not a body-axis convention. Northwestern’s official rotation-matrix supplement distinguishes these multiplication choices.

A column vector places the components vertically. A rotation matrix is a three-by-three table that multiplies that column on the left. Each output component is the sum of a matrix row times the input components. Write Rx, Ry and Rz for positive quarter turns about the named fixed axes:

Rx(+90°) Ry(+90°) Rz(+90°)
[1, 0, 0]
[0, 0, −1]
[0, 1, 0]
[0, 0, 1]
[0, 1, 0]
[−1, 0, 0]
[0, −1, 0]
[1, 0, 0]
[0, 0, 1]

For example, Rx sends positive y to positive z and leaves x unchanged. Ry sends positive z to positive x, so it sends positive x to negative z. The matrices contain only 0, +1 and −1. Repeating a quarter turn four times gives the identity matrix I, which leaves every vector unchanged.

Calculate the two specified paths

Start v0 = (1, 0, 0). Apply Rx first: v1 = (1, 0, 0), because the vector lies on the rotation axis. Apply Ry next: v2 = (0, 0, −1). In symbols, v2 = RyRxv0. The later operation multiplies on the left; the first operation is the rightmost matrix.

Reverse the chronological sequence. Ry first gives (0, 0, −1); Rx then sends that direction to (0, 1, 0). Thus RxRyv0 ≠ RyRxv0. Operations commute when swapping their order leaves the result unchanged. These two rotations do not commute. This does not say that every pair differs: turns about the same axis commute, and some particular vectors can hide a difference between matrices.

The figures use an oblique projection, a declared mapping of three coordinates onto two page coordinates: u = x + 0.45y and w = z + 0.30y, with w upward. It distorts lengths and angles. The plotted points are vector tips expressed in the fixed frame; dashed connectors show their discrete order, not a continuous physical trajectory. v0, v1 and v2 mean initial, after first turn and after second turn.

Two oblique-projection panels keep the same fixed global axes. Rx then Ry leaves the x vector unchanged at its first step and ends at negative z; Ry then Rx passes through negative z and ends at positive y.
Original constructed vector geometry from the delivered model. Dashed tip connectors indicate order, and the first x-turn has no vector-tip displacement. Full-size PNG · editable SVG — reader ZIP; extract assets/ordered-vector-paths.svg.

Perform the labelled paper-triad experiment

  1. Keep two paper strips fixed on the desk as perpendicular x and y directions, with x right and y away. Stand the third strip upward with a folded foot for z. Label their common origin and positive ends. This is a conceptual reference, not a metrology fixture.
  2. Draw an arrow on the separate card and begin with it pointing along +x. Predict the x-then-y final vector before moving it. In a copy of the blank records — reader ZIP; extract data/blank-records.json, enter the three predicted components as observed_final and change provenance, the entry-source label, to reader_observation. Keep the original null observations unchanged.
  3. Imagine or carry out the positive x quarter turn about the fixed desk x direction. The arrow still points +x even though the card can change orientation around that arrow. Then use the same fixed desk y direction for the second positive quarter turn. Predict −z. Do not rotate the reference strips with the card.
  4. Restore the arrow to +x. Reverse the operations: the positive y turn gives −z and the positive x turn then gives +y. The two operations and their positive signs are unchanged; only their chronological order differs.
  5. Use four positive x quarter turns as a control. The final vector must return to +x. Restore the original two-step sequence and verify its predicted −z result again.
  6. Record how you obtained any entry: hand calculation, approximate paper observation or model output. The program’s reader_observation label records your entry; it does not turn it into a validated physical measurement.

Read the complete products, not just one arrow

A basis here is the three unit vectors ex = (1, 0, 0), ey = (0, 1, 0) and ez = (0, 0, 1). The columns of a matrix R are R ex, R ey and R ez. The two composites are:

RyRx RxRy
[0, 1, 0]
[0, 0, −1]
[−1, 0, 0]
[0, 0, 1]
[1, 0, 0]
[0, 1, 0]

Orthogonality means that these columns are mutually perpendicular unit vectors. RT means the transpose, made by exchanging rows and columns; RTR = I expresses orthogonality. The determinant is a signed volume-scale number; +1 here preserves right-handedness, while −1 would indicate a reflection. The model’s products preserve vector length. These properties and the distinction from a general matrix are explained in Northwestern’s first rotation-matrix supplement.

The two model-computed composite matrices are shown with their three rotated basis-vector columns in one fixed global frame. Both products are orthogonal with determinant plus one, but their first columns point in different directions.
Original model-derived products and transformed triads, using the same oblique projection. Colors tie each matrix column to its basis arrow. All values are constructed, not measured. Full-size PNG · editable SVG — reader ZIP; extract assets/composite-basis-products.svg.

A zero vector stays zero under both products and cannot reveal orientation. More generally, observing one vector is not a complete three-axis orientation measurement. The three basis columns show why a full matrix is more informative than a single endpoint.

Run the complete validated model

Each JSON record gives a vector, chronological steps, an observed_final entry and a provenance label describing where that entry came from. JSON null means no observation, not zero. The supplied blank file keeps observed_final and the calculated observation residual unknown. A residual is the entered vector minus the model’s predicted final vector, component by component.

The software accepts x/y/z axes, nonboolean integer quarter_turns from −1,000,000 to +1,000,000, up to 64 steps and three finite numeric vector components with magnitude at most 109. It reduces turn counts modulo four, meaning only their remainder after division by four affects the rotation. A document contains 1–128 uniquely named records and at most 256 kibibytes (KiB), where one KiB is 1,024 bytes. Files use the 8-bit Unicode Transformation Format (UTF-8) character encoding. These are declared software limits, not mechanical ratings. It rejects strings pretending to be numbers, Boolean true/false values in numeric fields, partial vectors, unknown fields/provenance, duplicate identifiers or JSON keys, and nonfinite values such as infinity or an undefined numeric result. Integer matrices and integer example vectors remain exact; optional fractional numeric entries use Python’s floating-point representation.

This is the entire model and record analyzer. It writes its report to standard output; it does not alter the input files or send device commands.

"""Exact quarter-turn matrices about FIXED global axes; column vectors.

Standard library. Tested with CPython 3.12.14. No device control or
orientation measurement. Later operations multiply on the LEFT.
"""
import argparse
import json
import math
from pathlib import Path
import re

IDENTITY=((1,0,0),(0,1,0),(0,0,1))
QUARTER={
    'x':((1,0,0),(0,0,-1),(0,1,0)),
    'y':((0,0,1),(0,1,0),(-1,0,0)),
    'z':((0,-1,0),(1,0,0),(0,0,1)),
}


def _multiply(a,b):
    return [[sum(a[i][k]*b[k][j] for k in range(3))
             for j in range(3)] for i in range(3)]


def _vector(value):
    if not isinstance(value,(list,tuple)) or len(value)!=3:
        raise ValueError('a vector needs exactly three numbers')
    if any(type(x) not in (int,float) or abs(x)>10**9
           or not math.isfinite(x) for x in value):
        raise ValueError('vector numbers must be finite, nonboolean and bounded by 1e9')
    return list(value)


def quarter_matrix(axis,quarter_turns):
    if type(axis) is not str or axis not in QUARTER:
        raise ValueError('axis must be x, y or z in the fixed global frame')
    if type(quarter_turns) is not int or abs(quarter_turns)>10**6:
        raise ValueError('quarter_turns must be an integer between -1000000 and 1000000')
    result=[list(row) for row in IDENTITY]
    for unused in range(quarter_turns%4):
        result=_multiply(QUARTER[axis],result)
    return result


def apply_sequence(vector,steps):
    current=_vector(vector)
    if not isinstance(steps,(list,tuple)) or len(steps)>64:
        raise ValueError('steps must be a list of at most 64 operations')
    total=[list(row) for row in IDENTITY]
    states=[current[:]]
    for step in steps:
        if not isinstance(step,dict) or set(step)!={'axis','quarter_turns'}:
            raise ValueError('each step needs only axis and quarter_turns')
        matrix=quarter_matrix(step['axis'],step['quarter_turns'])
        current=[sum(matrix[i][j]*current[j] for j in range(3)) for i in range(3)]
        total=_multiply(matrix,total)
        states.append(current[:])
    return {'states':states,'final_vector':current,'composite_matrix':total}


def _document(document):
    if not isinstance(document,dict) or set(document)!={'format','records'}:
        raise ValueError('document needs only format and records')
    if document['format']!='rotation-lab-v1':
        raise ValueError('unknown record format')
    rows=document['records']
    if not isinstance(rows,list) or not 1<=len(rows)<=128:
        raise ValueError('records must contain 1 to 128 rows')
    return rows


def analyze_records(document):
    rows=_document(document)
    seen=set()
    output=[]
    required={'record_id','vector','steps','observed_final','provenance'}
    for row in rows:
        if not isinstance(row,dict) or set(row)!=required:
            raise ValueError('unexpected record fields')
        name=row['record_id']
        if type(name) is not str or re.fullmatch(r'[A-Za-z0-9_.-]{1,48}',name) is None:
            raise ValueError('record_id must be 1 to 48 letters, digits, dots, hyphens or underscores')
        if name in seen:
            raise ValueError('duplicate record_id')
        seen.add(name)
        provenance=row['provenance']
        if provenance not in ('blank','constructed','reader_observation'):
            raise ValueError('unknown provenance')
        prediction=apply_sequence(row['vector'],row['steps'])
        observed=row['observed_final']
        if provenance=='blank':
            if observed is not None:
                raise ValueError('a blank record must keep observed_final null')
            residual=None
        else:
            observed=_vector(observed)
            residual=[a-b for a,b in zip(observed,prediction['final_vector'])]
        output.append({'record_id':name,'provenance':provenance,
                       'prediction':prediction,'observed_final':observed,
                       'residual':residual})
    return output


def _unique(pairs):
    result={}
    for key,value in pairs:
        if key in result:
            raise ValueError('duplicate JSON key')
        result[key]=value
    return result


def _nonfinite(unused):
    raise ValueError('nonfinite JSON constant is not accepted')


def load_records(text):
    if type(text) is not str or len(text.encode('utf-8'))>262144:
        raise ValueError('input must be UTF-8 text no larger than 256 KiB')
    try:
        document=json.loads(text,object_pairs_hook=_unique,parse_constant=_nonfinite)
    except RecursionError as error:
        raise ValueError('JSON nesting is too deep') from error
    _document(document)
    return document


def main():
    parser=argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--records',required=True,type=Path)
    args=parser.parse_args()
    try:
        if args.records.stat().st_size>262144:
            raise ValueError('input larger than 256 KiB')
        document=load_records(args.records.read_text(encoding='utf-8'))
        result=analyze_records(document)
    except (ValueError,OSError,UnicodeError) as error:
        parser.error(str(error))
    report={'kind':'fixed-global-axis mathematical prediction',
            'physical_test':False,'records':result}
    print(json.dumps(report,indent=2,allow_nan=False))


if __name__=='__main__':
    main()

From the extracted folder run the following. Keep generated reports separate from the original records:

python3 -m unittest discover -v
python3 rotation_lab.py --records data/constructed-records.json
python3 rotation_lab.py --records data/blank-records.json
python3 rotation_lab.py --records data/restored-records.json

The supplied complete tests — reader ZIP; extract test_rotation_lab.py exercise the two hand-derived ordered examples, intermediate vectors and products, four-turn identity, reversed inverses, norm, determinant and orthogonality, all 24 orientations generated by these axis-aligned quarter turns, malformed/Boolean/nonfinite inputs, blank observations and the actual command-line entry point. All 27 supplied tests passed on the recorded host. This finite 24-orientation set does not include every possible three-dimensional rotation.

Inject an order fault and restore the record

In constructed-records.json — reader ZIP; extract data/constructed-records.json, FAULT_wrong_order deliberately supplies the reverse-order vector (0, 1, 0) while retaining the x-then-y sequence. Its residual is (0, 1, 1), because (0, 1, 0) − (0, 0, −1) = (0, 1, 1). This is a known numerical fault injection. A nonzero residual alone does not diagnose what happened in a real process.

Copy that record, replace its constructed entered vector with (0, 0, −1), and keep the x-then-y steps. The residual becomes (0, 0, 0), as in restored-records.json — reader ZIP; extract data/restored-records.json. Preserve the original fault file. Agreement proves consistency with this declared model, not correct operation of a machine. The blank file deliberately produces null observed_final and null residual; missing information is never silently replaced by a zero vector.

Conditions and limits

The rotation axes pass through one common origin and stay fixed. Only exact multiples of 90 degrees about coordinate axes are implemented. There is no translation, arbitrary-angle interpolation, moving-axis interface, mechanical backlash, sensor noise, calibration, force or dynamics model. The two-dimensional projection is only for the diagrams. The exact matrix results, not apparent angles or distances on that projection, are authoritative.

These are original paper/software examples with host tests. No robot or machine was commanded, no firmware was compiled, no target application was executed and no orientation was measured for this lesson. The optional figure generator is fixed to the supplied worked examples and layout; arbitrary custom records need their own plotting review. Pre-rendered PNGs are included, so no rendering dependency is needed for the experiment.

Challenge: undo both turns

After x then y, which chronological inverse sequence restores every starting vector? Would applying −x then −y always work?

Worked answer

Undo the last operation first: apply y with −1 quarter turn, then x with −1. The full product is Rx−1Ry−1RyRx = I. Reversing that inverse order is generally wrong. The provided inverse-sequence test uses a non-axis vector as well, so a coincident endpoint cannot hide a missing inverse operation.

Sources and a related experiment

The official Northwestern supplements support the rotation-matrix properties and the fixed-frame multiplication convention. Massachusetts Institute of Technology (MIT)’s rotation-representation notes emphasize stating the reference frame and representation clearly. Our exact worked matrices, code, data, diagrams and paper procedure are original. See the primary-source index — reader ZIP; extract source-index.html and scope notes — reader ZIP; extract source-notes.txt; no third-party manuals or artwork are bundled.

For a distinct use of three-dimensional coordinates, compare the cone–vee–flat constraint experiment. That lesson studies small first-order constrained motion; the present lesson applies finite quarter turns in a fixed global frame. Neither is a physical repeatability or orientation-calibration result.

📡Broadcast the signal — amplify the connection.

Leave a Reply