Data Structures | Macros | Typedefs | Functions
3x3 floating point matrices

Definition and operations for 3x3 matrices. More...

Data Structures

struct  _Eina_Matrix3
 A 3x3 floating point matrix. More...
 

Macros

#define EINA_MATRIX3_FORMAT   "g %g %g | %g %g %g | %g %g %g"
 Helper macro for printf formatting.
 
#define EINA_MATRIX3_ARGS(m)
 Helper macro for printf formatting arg. More...
 

Typedefs

typedef struct _Eina_Matrix3 Eina_Matrix3
 A 3x3 floating point matrix.
 

Functions

EINA_API Eina_Matrix_Type eina_matrix3_type_get (const Eina_Matrix3 *m)
 Returns the type of the given floating point matrix. More...
 
EINA_API void eina_matrix3_values_set (Eina_Matrix3 *m, double xx, double xy, double xz, double yx, double yy, double yz, double zx, double zy, double zz)
 Sets the values of the coefficients of the given floating point matrix. More...
 
EINA_API void eina_matrix3_values_get (const Eina_Matrix3 *m, double *xx, double *xy, double *xz, double *yx, double *yy, double *yz, double *zx, double *zy, double *zz)
 Gets the values of the coefficients of the given floating point matrix. More...
 
EINA_API void eina_matrix3_fixed_values_get (const Eina_Matrix3 *m, Eina_F16p16 *xx, Eina_F16p16 *xy, Eina_F16p16 *xz, Eina_F16p16 *yx, Eina_F16p16 *yy, Eina_F16p16 *yz, Eina_F16p16 *zx, Eina_F16p16 *zy, Eina_F16p16 *zz)
 Gets the values of the coefficients of the given fixed point matrix. More...
 
EINA_API void eina_matrix3_matrix3_f16p16_to (const Eina_Matrix3 *m, Eina_Matrix3_F16p16 *fm)
 Transforms the given floating point matrix to the given fixed point matrix. More...
 
EINA_API Eina_Bool eina_matrix3_equal (const Eina_Matrix3 *m1, const Eina_Matrix3 *m2)
 Checks whether the two matrices are equivalent. More...
 
EINA_API void eina_matrix3_compose (const Eina_Matrix3 *m1, const Eina_Matrix3 *m2, Eina_Matrix3 *dst)
 Sets dst as the matrix multiplication (composition) of two matrices. More...
 
EINA_API void eina_matrix3_translate (Eina_Matrix3 *m, double tx, double ty)
 Sets the matrix values for a translation operation. More...
 
EINA_API void eina_matrix3_scale (Eina_Matrix3 *m, double sx, double sy)
 Sets the matrix values for a scaling operation. More...
 
EINA_API void eina_matrix3_rotate (Eina_Matrix3 *m, double rad)
 Sets the matrix values for a rotation operation. More...
 
EINA_API void eina_matrix3_identity (Eina_Matrix3 *m)
 Sets the given floating point matrix to the identity matrix. More...
 
EINA_API double eina_matrix3_determinant (const Eina_Matrix3 *m)
 Calculates the determinant of the given matrix. More...
 
EINA_API void eina_matrix3_divide (Eina_Matrix3 *m, double scalar)
 Divides the given matrix by a scalar number. More...
 
EINA_API void eina_matrix3_inverse (const Eina_Matrix3 *m, Eina_Matrix3 *m2)
 Computes the inverse of the given matrix. More...
 
EINA_API void eina_matrix3_transpose (const Eina_Matrix3 *m, Eina_Matrix3 *a)
 Computes the transpose of the given matrix. More...
 
EINA_API void eina_matrix3_cofactor (const Eina_Matrix3 *m, Eina_Matrix3 *a)
 Computes the cofactor of the given matrix. More...
 
EINA_API void eina_matrix3_adjoint (const Eina_Matrix3 *m, Eina_Matrix3 *a)
 Computes the adjoint of the given matrix. More...
 
EINA_API void eina_matrix3_point_transform (const Eina_Matrix3 *m, double x, double y, double *xr, double *yr)
 Computes the transform of a 2D point using the given matrix. More...
 
EINA_API void eina_matrix3_rectangle_transform (const Eina_Matrix3 *m, const Eina_Rectangle *r, const Eina_Quad *q)
 Computes the transformation of a rectangle using the given matrix. More...
 
EINA_API Eina_Bool eina_matrix3_quad_quad_map (Eina_Matrix3 *m, const Eina_Quad *src, const Eina_Quad *dst)
 Creates a projective matrix that maps a quadrangle to a quadrangle. More...
 
EINA_API Eina_Bool eina_matrix3_square_quad_map (Eina_Matrix3 *m, const Eina_Quad *q)
 Creates a matrix for unit-square to quad mapping. More...
 
EINA_API Eina_Bool eina_matrix3_quad_square_map (Eina_Matrix3 *m, const Eina_Quad *q)
 Creates a matrix for mapping squares to match quad. More...
 
EINA_API void eina_matrix3_array_set (Eina_Matrix3 *m, const double *v)
 Sets matrix values using an array. More...
 
EINA_API void eina_matrix3_copy (Eina_Matrix3 *dst, const Eina_Matrix3 *src)
 Copies a matrix. More...
 
EINA_API void eina_matrix3_multiply (Eina_Matrix3 *out, const Eina_Matrix3 *mat_a, const Eina_Matrix3 *mat_b)
 Multiplies two matrices. More...
 
EINA_API void eina_matrix3_multiply_copy (Eina_Matrix3 *out, const Eina_Matrix3 *mat_a, const Eina_Matrix3 *mat_b)
 Multiplies two matrices without overwriting them. More...
 
EINA_API void eina_matrix3_scale_transform_set (Eina_Matrix3 *out, double s_x, double s_y)
 Sets the scale parameters (XX, YY) of a matrix. More...
 
EINA_API void eina_matrix3_position_transform_set (Eina_Matrix3 *out, const double p_x, const double p_y)
 Sets the positional parameters (XZ, YZ) of a matrix. More...
 
EINA_API void eina_normal3_matrix_get (Eina_Matrix3 *out, const Eina_Matrix4 *m)
 Sets normal of the given matrix. More...
 
EINA_API void eina_matrix3_matrix4_to (Eina_Matrix4 *m4, const Eina_Matrix3 *m3)
 Converts an Eina_Matrix3 into an Eina_Matrix4. More...
 

Detailed Description

Definition and operations for 3x3 matrices.

Macro Definition Documentation

◆ EINA_MATRIX3_ARGS

#define EINA_MATRIX3_ARGS (   m)
Value:
(m)->xx, (m)->xy, (m)->xz, \
(m)->yx, (m)->yy, (m)->yz, \
(m)->zx, (m)->zy, (m)->zz

Helper macro for printf formatting arg.

Function Documentation

◆ eina_matrix3_type_get()

EINA_API Eina_Matrix_Type eina_matrix3_type_get ( const Eina_Matrix3 m)

Returns the type of the given floating point matrix.

Parameters
[in]mThe floating point matrix.
Returns
The type of the matrix.

This function returns the type of the matrix m. No check is done on m.

Since
1.14

References EINA_DBL_EQ, EINA_MATRIX_TYPE_AFFINE, EINA_MATRIX_TYPE_IDENTITY, and EINA_MATRIX_TYPE_PROJECTIVE.

Referenced by eina_matrix3_multiply().

◆ eina_matrix3_values_set()

EINA_API void eina_matrix3_values_set ( Eina_Matrix3 m,
double  xx,
double  xy,
double  xz,
double  yx,
double  yy,
double  yz,
double  zx,
double  zy,
double  zz 
)

Sets the values of the coefficients of the given floating point matrix.

Parameters
[out]mThe floating point matrix.
[in]xxThe first coefficient value.
[in]xyThe second coefficient value.
[in]xzThe third coefficient value.
[in]yxThe fourth coefficient value.
[in]yyThe fifth coefficient value.
[in]yzThe sixth coefficient value.
[in]zxThe seventh coefficient value.
[in]zyThe eighth coefficient value.
[in]zzThe ninth coefficient value.

This function sets the values of the coefficients of the matrix m. No check is done on m.

See also
eina_matrix3_values_get()
Since
1.14

◆ eina_matrix3_values_get()

EINA_API void eina_matrix3_values_get ( const Eina_Matrix3 m,
double *  xx,
double *  xy,
double *  xz,
double *  yx,
double *  yy,
double *  yz,
double *  zx,
double *  zy,
double *  zz 
)

Gets the values of the coefficients of the given floating point matrix.

Parameters
[in]mThe floating point matrix.
[out]xxThe first coefficient value.
[out]xyThe second coefficient value.
[out]xzThe third coefficient value.
[out]yxThe fourth coefficient value.
[out]yyThe fifth coefficient value.
[out]yzThe sixth coefficient value.
[out]zxThe seventh coefficient value.
[out]zyThe eighth coefficient value.
[out]zzThe ninth coefficient value.

This function gets the values of the coefficients of the matrix m. No check is done on m.

See also
eina_matrix3_values_set()
Since
1.14

◆ eina_matrix3_fixed_values_get()

EINA_API void eina_matrix3_fixed_values_get ( const Eina_Matrix3 m,
Eina_F16p16 xx,
Eina_F16p16 xy,
Eina_F16p16 xz,
Eina_F16p16 yx,
Eina_F16p16 yy,
Eina_F16p16 yz,
Eina_F16p16 zx,
Eina_F16p16 zy,
Eina_F16p16 zz 
)

Gets the values of the coefficients of the given fixed point matrix.

Parameters
[in]mThe fixed point matrix.
[out]xxThe first coefficient value.
[out]xyThe second coefficient value.
[out]xzThe third coefficient value.
[out]yxThe fourth coefficient value.
[out]yyThe fifth coefficient value.
[out]yzThe sixth coefficient value.
[out]zxThe seventh coefficient value.
[out]zyThe eighth coefficient value.
[out]zzThe nine-th coefficient value.

This function gets the values of the coefficients of the matrix m. No check is done on m.

See also
eina_matrix3_values_set()
Since
1.14

References eina_f16p16_double_from().

Referenced by eina_matrix3_matrix3_f16p16_to().

◆ eina_matrix3_matrix3_f16p16_to()

EINA_API void eina_matrix3_matrix3_f16p16_to ( const Eina_Matrix3 m,
Eina_Matrix3_F16p16 fm 
)

Transforms the given floating point matrix to the given fixed point matrix.

Parameters
[in]mThe floating point matrix.
[out]fmThe fixed point matrix.

This function transforms the floating point matrix m to a fixed point matrix and stores the coefficients into the fixed point matrix fm.

Since
1.14

References eina_matrix3_fixed_values_get().

◆ eina_matrix3_equal()

EINA_API Eina_Bool eina_matrix3_equal ( const Eina_Matrix3 m1,
const Eina_Matrix3 m2 
)

Checks whether the two matrices are equivalent.

Parameters
[in]m1The first matrix.
[in]m2The second matrix.
Returns
EINA_TRUE if the two matrices are equal, EINA_FALSE otherwise.

This function returns EINA_TRUE if the matrices m1 and m2 are equal, EINA_FALSE otherwise. No check is done on the matrices.

Since
1.14

References EINA_DBL_EQ, EINA_FALSE, EINA_TRUE, _Eina_Matrix3::xx, _Eina_Matrix3::xy, _Eina_Matrix3::xz, _Eina_Matrix3::yx, _Eina_Matrix3::yy, _Eina_Matrix3::yz, _Eina_Matrix3::zx, _Eina_Matrix3::zy, and _Eina_Matrix3::zz.

◆ eina_matrix3_compose()

EINA_API void eina_matrix3_compose ( const Eina_Matrix3 m1,
const Eina_Matrix3 m2,
Eina_Matrix3 dst 
)

Sets dst as the matrix multiplication (composition) of two matrices.

Parameters
[in]m1The first matrix. Must be non-NULL.
[in]m2The second matrix. Must be non-NULL.
[out]dstThe results matrix.

In matrix multiplication, AB, the resultant matrix is created from the rows of A multiplied against the columns of B and summed. This is not commutative; i.e. AB != BA, so the ordering of arguments m1 and m2 matters.

Since
1.14

Referenced by eina_matrix3_multiply(), eina_matrix3_quad_quad_map(), eina_matrix3_rotate(), eina_matrix3_scale(), and eina_matrix3_translate().

◆ eina_matrix3_translate()

EINA_API void eina_matrix3_translate ( Eina_Matrix3 m,
double  tx,
double  ty 
)

Sets the matrix values for a translation operation.

Parameters
[out]mThe matrix.
[in]txThe X coordinate translation.
[in]tyThe Y coordinate translation.
Since
1.14

References eina_matrix3_compose().

◆ eina_matrix3_scale()

EINA_API void eina_matrix3_scale ( Eina_Matrix3 m,
double  sx,
double  sy 
)

Sets the matrix values for a scaling operation.

Parameters
[out]mThe matrix.
[in]sxThe X coordinate scaling factor.
[in]syThe Y coordinate scaling factor.
Since
1.14

References eina_matrix3_compose().

◆ eina_matrix3_rotate()

EINA_API void eina_matrix3_rotate ( Eina_Matrix3 m,
double  rad 
)

Sets the matrix values for a rotation operation.

Parameters
[out]mThe matrix.
[in]radThe number of radians to rotate.
Since
1.14

References eina_matrix3_compose().

◆ eina_matrix3_identity()

EINA_API void eina_matrix3_identity ( Eina_Matrix3 m)

Sets the given floating point matrix to the identity matrix.

Parameters
[out]mThe matrix to set to identity.

This function sets m to the identity matrix. No check is done on m.

Since
1.14

Referenced by eina_matrix3_inverse(), eina_matrix3_position_transform_set(), and eina_matrix3_scale_transform_set().

◆ eina_matrix3_determinant()

EINA_API double eina_matrix3_determinant ( const Eina_Matrix3 m)

Calculates the determinant of the given matrix.

Parameters
[in]mThe matrix.
Returns
The determinant.

This function returns the determinant of the matrix m. No check is done on m.

Since
1.14

Referenced by eina_matrix3_inverse().

◆ eina_matrix3_divide()

EINA_API void eina_matrix3_divide ( Eina_Matrix3 m,
double  scalar 
)

Divides the given matrix by a scalar number.

Parameters
[in,out]mThe matrix.
[in]scalarThe scalar number.

This function divides the matrix m by scalar. No check is done on m.

Since
1.14

Referenced by eina_matrix3_inverse(), and eina_matrix3_quad_square_map().

◆ eina_matrix3_inverse()

EINA_API void eina_matrix3_inverse ( const Eina_Matrix3 m,
Eina_Matrix3 m2 
)

Computes the inverse of the given matrix.

Parameters
[in]mThe source matrix.
[out]m2The inverse matrix.

This function inverts the matrix m and stores the result in m2. No check is done on m or m2. If m cannot be inverted, then m2 is set to the identity matrix.

Since
1.14

References EINA_DBL_EQ, eina_matrix3_adjoint(), eina_matrix3_determinant(), eina_matrix3_divide(), and eina_matrix3_identity().

Referenced by eina_matrix3_quad_square_map().

◆ eina_matrix3_transpose()

EINA_API void eina_matrix3_transpose ( const Eina_Matrix3 m,
Eina_Matrix3 a 
)

Computes the transpose of the given matrix.

Parameters
[in]mThe source matrix.
[out]aThe transposed matrix.

This function transposes the matrix m and stores the result in a. No check is done on m or a. The transpose of a matrix essentially flips a matrix over its diagonal.

Since
1.14

Referenced by eina_matrix3_adjoint().

◆ eina_matrix3_cofactor()

EINA_API void eina_matrix3_cofactor ( const Eina_Matrix3 m,
Eina_Matrix3 a 
)

Computes the cofactor of the given matrix.

Parameters
[in]mThe source matrix.
[out]aThe cofactored matrix.

This function cofactors the matrix m and stores the result in a. No check is done on m or a. The cofactor of a matrix3 at row i, column j is computed by taking the determinant of the submatrix formed by deleting the i-th row and j-th column, and then multiplying by (-1)^(i+j).

Since
1.14

Referenced by eina_matrix3_adjoint().

◆ eina_matrix3_adjoint()

EINA_API void eina_matrix3_adjoint ( const Eina_Matrix3 m,
Eina_Matrix3 a 
)

Computes the adjoint of the given matrix.

Parameters
[in]mThe matrix to be adjointed.
[out]aThe adjoint matrix.

This function finds the adjoint of the matrix m and stores the result in a. No check is done on m or a. The adjoint of a matrix3 is effectively the transpose of its cofactor.

Since
1.14

References eina_matrix3_cofactor(), and eina_matrix3_transpose().

Referenced by eina_matrix3_inverse().

◆ eina_matrix3_point_transform()

EINA_API void eina_matrix3_point_transform ( const Eina_Matrix3 m,
double  x,
double  y,
double *  xr,
double *  yr 
)

Computes the transform of a 2D point using the given matrix.

Parameters
[in]mThe transformation matrix to apply.
[in]xThe x point to be transformed.
[in]yThe y point to be transformed.
[out]xrThe transformed x point.
[out]yrThe transformed y point.

Applies the transformation matrix m to the point (x,y), and stores the result in (*xr,*yr). No check is done on m; xr and yr must point to valid memory. A fast-path is included for if the zx and zy components of the matrix are zero.

Since
1.14

References EINA_DBL_EQ.

Referenced by eina_matrix3_rectangle_transform().

◆ eina_matrix3_rectangle_transform()

EINA_API void eina_matrix3_rectangle_transform ( const Eina_Matrix3 m,
const Eina_Rectangle r,
const Eina_Quad q 
)

Computes the transformation of a rectangle using the given matrix.

Parameters
[in]mThe transformation matrix to apply.
[in]rThe rectangle to be transformed.
[out]qThe resultant transformed points.

Performs a point transformation of each corner of the rectangle r, and stores the result in the quadrangle q. No checks are done on the inputs, and q must point to valid memory.

Since
1.14

References eina_matrix3_point_transform().

◆ eina_matrix3_quad_quad_map()

EINA_API Eina_Bool eina_matrix3_quad_quad_map ( Eina_Matrix3 m,
const Eina_Quad src,
const Eina_Quad dst 
)

Creates a projective matrix that maps a quadrangle to a quadrangle.

Parameters
[out]mThe transformation matrix to create.
[in]srcThe source quadrangle.
[in]dstThe destination quadrangle.
Returns
EINA_TRUE if matrix could be successfully created, EINA_FALSE otherwise.

Calculates a matrix m that can be used to transform from an arbitrary source quadrangle src to another arbitrary quadrangle dst.

References EINA_FALSE, eina_matrix3_compose(), eina_matrix3_quad_square_map(), eina_matrix3_square_quad_map(), and EINA_TRUE.

◆ eina_matrix3_square_quad_map()

EINA_API Eina_Bool eina_matrix3_square_quad_map ( Eina_Matrix3 m,
const Eina_Quad q 
)

Creates a matrix for unit-square to quad mapping.

Parameters
[out]mThe transformation matrix to create.
[in]qThe source quadrangle.
Returns
EINA_TRUE if matrix could be successfully created, EINA_FALSE otherwise.

Calculates a matrix m that can be used to transform an arbitrary quadrangle q into a square. If q is a parallelogram, then a fast path affine transformation is used, otherwise it computes the matrix using a full projective transformation operation. No other checks are done on m or q.

Since
1.14

References EINA_DBL_EQ, EINA_FALSE, and EINA_TRUE.

Referenced by eina_matrix3_quad_quad_map(), and eina_matrix3_quad_square_map().

◆ eina_matrix3_quad_square_map()

EINA_API Eina_Bool eina_matrix3_quad_square_map ( Eina_Matrix3 m,
const Eina_Quad q 
)

Creates a matrix for mapping squares to match quad.

Parameters
[out]mThe transformation matrix to create.
[in]qThe source quadrangle.
Returns
EINA_FALSE on successful transform creation, EINA_FALSE otherwise.

Calculates a matrix m that can be used to transform a square to fit a given quadrangle. The created matrix will always have its zz element equal to 1.0. The m matrix and q quad must be valid memory.

Since
1.14

References EINA_DBL_EQ, EINA_FALSE, eina_matrix3_divide(), eina_matrix3_inverse(), eina_matrix3_square_quad_map(), and EINA_TRUE.

Referenced by eina_matrix3_quad_quad_map().

◆ eina_matrix3_array_set()

EINA_API void eina_matrix3_array_set ( Eina_Matrix3 m,
const double *  v 
)

Sets matrix values using an array.

Parameters
[out]mThe result matrix.
[in]vThe array[9] of values.

Uses the first 9 elements in the given C array v to set the values in the matrix m. The values will be set in the order of the elements in the Eina_Matrix3 structure.

Since
1.17

◆ eina_matrix3_copy()

EINA_API void eina_matrix3_copy ( Eina_Matrix3 dst,
const Eina_Matrix3 src 
)

Copies a matrix.

Parameters
[out]dstCopy of the matrix.
[in]srcThe matrix to copy.
Since
1.16

Referenced by eina_matrix3_multiply(), and eina_matrix3_multiply_copy().

◆ eina_matrix3_multiply()

EINA_API void eina_matrix3_multiply ( Eina_Matrix3 out,
const Eina_Matrix3 mat_a,
const Eina_Matrix3 mat_b 
)

Multiplies two matrices.

Parameters
[out]outThe resulting matrix.
[in]mat_aThe first member of the multiplication.
[in]mat_bThe second member of the multiplication.

out must not point to the same structure as mat_a or mat_b, else the calculation results will be incorrect. Use eina_matrix3_multiply_copy() instead in this case.

Since
1.17

References eina_matrix3_compose(), eina_matrix3_copy(), eina_matrix3_type_get(), and EINA_MATRIX_TYPE_IDENTITY.

Referenced by eina_matrix3_multiply_copy().

◆ eina_matrix3_multiply_copy()

EINA_API void eina_matrix3_multiply_copy ( Eina_Matrix3 out,
const Eina_Matrix3 mat_a,
const Eina_Matrix3 mat_b 
)

Multiplies two matrices without overwriting them.

Parameters
[out]outThe resulting matrix.
[in]mat_aThe first member of the multiplication.
[in]mat_bThe second member of the multiplication.

Safely multiplies mat_a and mat_b by checking if the out parameter points to either of them, and if so uses a temporary matrix for the intermediary calculations.

Since
1.17

References eina_matrix3_copy(), and eina_matrix3_multiply().

◆ eina_matrix3_scale_transform_set()

EINA_API void eina_matrix3_scale_transform_set ( Eina_Matrix3 out,
double  s_x,
double  s_y 
)

Sets the scale parameters (XX, YY) of a matrix.

Parameters
[out]outThe resulting matrix.
[in]s_xThe scale value for x.
[in]s_yThe scale value for y.

Sets only the XX and YY components of the matrix, leaving the rest of the matrix as it was.

Since
1.17

References eina_matrix3_identity().

◆ eina_matrix3_position_transform_set()

EINA_API void eina_matrix3_position_transform_set ( Eina_Matrix3 out,
const double  p_x,
const double  p_y 
)

Sets the positional parameters (XZ, YZ) of a matrix.

Parameters
[out]outThe resulting matrix.
[in]p_xThe position value for x.
[in]p_yThe position value for y.

Sets only the XZ and YZ components of the matrix, leaving the rest of the matrix as it was.

Since
1.17

References eina_matrix3_identity().

◆ eina_normal3_matrix_get()

EINA_API void eina_normal3_matrix_get ( Eina_Matrix3 out,
const Eina_Matrix4 m 
)

Sets normal of the given matrix.

Parameters
[out]outThe resulting matrix.
[in]mThe matrix.
Since
1.17

◆ eina_matrix3_matrix4_to()

EINA_API void eina_matrix3_matrix4_to ( Eina_Matrix4 m4,
const Eina_Matrix3 m3 
)

Converts an Eina_Matrix3 into an Eina_Matrix4.

Parameters
[out]m3The destination Eina_Matrix3.
[in]m4The source Eina_Matrix4.
Since
1.15