expression
Distinguish points and directions in affine transforms
Homogeneous coordinates allow translation to be represented with matrix multiplication. Under a 2D affine transformation a point with w=1 receives translation, while a direction with w=0 does not. This example isolates the translation part of a 3x3 matrix using integer coordinates. It does not implement perspective projection. Expected result (NOT RUN): point: [6, 1, 1] direction: [1, 3, 0] Common mistake: Translating a direction vector as though it were a position. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
point [x, y, 1]; direction [dx, dy, 0]Working Example
Example Snippetrust
fn translate(p: [i32; 3]) -> [i32; 3] { [p[0] + 5*p[2], p[1] - 2*p[2], p[2]]}fn main() { println!("point: {:?}", translate([1, 3, 1])); println!("direction: {:?}", translate([1, 3, 0]));}