Notes, Definitions, ...

Table Of Contents

Matrix Multiplication Order of Operations is Important

The order of operations for graphics transformation matrix multiplication ("@") is important. A @ B is not the same as B @ A.

For example, you can use three transformation matrices to rotate an object in place...

You do this because rotation is around the coordinate system's origin (0,0,0). However, you want the object to rotate around its pivot point. So you temporally move the object to the coordinate system's origin, rotate the object, and then put it back.

Use a Combined Transformation Matrix to Generate New Coordinates

To create a combined transformation matrix ...

T4 = T3 @ T2 @ T1
Note: The first operation you want to do is the last one in the list of operations. In other words, read the operations from right to left. (First T1, then T2, then T3 ...)

To create new coordinates ...

import numpy as np

old_coords = np.array([x,y,z,1])

new_coords = T4 @ old_coords

Note: new_coords are [x', y', z', 1] (ignore the 1)

Coordinate Systems

Hardware computer graphics coordinate systems usually have their origin (0,0) in the upper left corner of the screen. X coordinates increase to the right and Y coordinates increase downward.

            wwwwwwwwwwwwwww
            w +x,+y
            w
            w

Centered (Cartesian) coordinate systems usually have their origin (0,0) in the center of the window.

                 |
           -x,+y | +x,+y
        ---------+--------- 
           -x,-y | +x,-y
                 |

Plots, histograms, etc. usually have their origin (0,0) in the lower left part of a window leaving room for text and other information. The X coordinates increasing to the right and Y coordinates increasing upward.

            w
            w    |
            w    | +x,+y
            w    +-------- 
            w
            wwwwwwwwwwwwwww 

Other coordinate systems have coordinates that range from 0.0 up to 1.0 (includes 0.0; excludes 1.0). This is often written "[0-1)" to indicate 1.0 is not included. Yet others use -1.0 to 1.0 (excluding -1.0 and 1.0).

Scaling Coordinates

In many cases the (data) coordinate system's range is not the same as the window's range. The (data) coordinates must be scaled to fit the window. In other word if the window's maximum width is 800 and the data's maximum width is not 800, the data's coordinate must be scaled to fit the window.

# ---- The following code assumes that both coordinate systems start at zero (origin 0,0).
# ---- If not, the following formulas must be modified.
# ---- Both the x and y coordinate must be scaled to fit the window.

DX = data_max_x_value
DY = data_max_y_value

WX = window_max_x_width
WY = window_max_y_height

# ---- these new coordinates will probably end up as floats

NEW_X = DATA_X * (DX/WX)
NEW_Y = DATA_Y * (DY/WY)

# ---- or if you want to force float coordinates

NEW_X = float(DATA_X * (DX/WX)
NEW_Y = float(DATA_Y * (DY/WY)

# ---- or if you want to force integer coordinates

NEW_X = round(DATA_X * (DX/WX))
NEW_Y = round(DATA_Y * (DY/WY))

Definitions

bounding boxA bounding box is an imaginary box that surrounds an object. It can be used check for selection, collision, or other activity. The bounding box is a rectangle that fully encloses the object.
normal vectorA vector to a surface which is perpendicular to the surface at a given point.
matrixA rectangular array of numbers (or other mathematical objects) for which operations such as addition and multiplication are defined.
pivot pointUsually the center point for rotating a graphics object. This is usually, but not always, within an object. For examples, if you have star data, you usually rotate the stars around the center of the earth, and do not rotate each star.
right-hand ruleIf you point the thumb of your right hand in the direction of the positive z-axis, then when you curl the fingers of that hand, they will curl in the direction from the positive x-axis towards the positive y-axis. If you are looking at the tip of your thumb, the curl will be in the counterclockwise direction.
Right-hand rule (Wikipedia)
vectorA quantity that has both magnitude and direction. A vector has magnitude and direction, but it does not have position.