Skip to content

Latest commit

 

History

History
49 lines (32 loc) · 812 Bytes

File metadata and controls

49 lines (32 loc) · 812 Bytes

Working with 3x3 Matrices

Identity Matrix

Get the identity matrix:

let identityMatrix = float3x3.identity

Translation Matrix

Create a translation matrix:

let translation = float3x3.translate(value: SIMD2<Float32>(x: 10, y: 5))

Rotation Matrix

Create a rotation matrix:

let rotation = float3x3.rotate(angle: Angle(degrees: 45))

Scaling Matrix

Create a scaling matrix:

let scaling = float3x3.scale(value: SIMD2<Float32>(x: 2, y: 3))

Codable Support

Encode and decode float3x3 matrices:

let matrix = float3x3.identity

// Encoding
let encoder = JSONEncoder()
let encodedData = try encoder.encode(matrix)

// Decoding
let decoder = JSONDecoder()
let decodedMatrix = try decoder.decode(float3x3.self, from: encodedData)