Skip to main content
API Reference com.nianticspatial.nsdk.utils

ImageMath

Kotlin wrapper for ARDK ImageMath functions. Each function returns an [android.graphics.Matrix] corresponding to a 3×3 affine or projective transformation.

Declaration

object ImageMath

Functions

NameTypeSummary
affineCropMatrix
Returns an affine transformation that crops the source size to match the aspect ratio of the target size.
affineFitMatrix
Returns an affine transformation that maps normalized coordinates in the source frame to normalized coordinates in the target frame.
affineInvertHorizontalMatrix
Returns an affine matrix for horizontal mirroring. Maps (u, v)(1 - u, v).
affineInvertVerticalMatrix
Returns an affine matrix for vertical mirroring. Maps (u, v)(u, 1 - v).
affineRotationMatrix
Returns an (u, v) -> (u', v') transformation that represents a 2D affine rotation.
affineScalingMatrix
Returns an (u, v) -> (u', v') transformation that represents a 2D affine scaling.
affineTranslationMatrix
Returns an (u, v) -> (u', v') transformation that represents a 2D affine translation.
calculateDeviceRotationMatrix
Returns an affine transform that rotates between two interface orientations around the center. This method models physical device rotation.
calculateViewRotationMatrix
Returns an affine transform that rotates between two interface orientations around the center. This method models UI rotation (opposite to physical device rotation).
concatenatingMatrix
Returns a new [Matrix] representing the concatenation of this matrix with another matrix, mimicking the behavior of CoreGraphics’ concatenating(_:) method on iOS.
displayTransformMatrix
Returns an affine transform [Matrix] that maps normalized image coordinates into a coordinate space suitable for rendering the camera image in the given viewport and orientation.
logAffinevoid
Logs the affine components of this [Matrix] in a readable format. Prints the matrix in iOS-style notation: a, b, c, d, tx, ty corresponding to the 2×3 affine transform: [ a c tx ] [ b d ty ]
logMatrixvoid
Logs the contents of this [Matrix] as a 3×3 matrix. The matrix values are printed in row-major order, as used internally by [android.graphics.Matrix]. Useful for debugging transformations like scale, rotation, skew, and perspective.
reprojectionMatrix
Returns a 3×3 homography matrix (android.graphics.Matrix) that reprojects image coordinates from a reference camera view into a target camera view. This is typically used to transform 2D image-space coordinates (normalized in [0..1]) from one camera perspective to another, e.g. for aligning visual overlays between AR frames.
reprojectPointsvoid
Applies a full 3×3 projective transformation (homography) to a set of 2D points, using this [Matrix] as a homography matrix. Unlike [Matrix.mapPoints], this method correctly applies the bottom row of the matrix and performs the required perspective divide. Transformed points are clamped to the [-1f..2f] range to ensure compatibility with UI constraints.