| // ***************************************************************************** |
| // Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // Contributors: |
| // Pierre Allard - initial API and implementation |
| // Regent L'Archeveque |
| // Sebastien Gemme |
| // |
| // SPDX-License-Identifier: EPL-1.0 |
| // ***************************************************************************** |
| |
| @GenModel(prefix="ApogyCommonMath", |
| childCreationExtenders="true", |
| extensibleProviderFactory="true", |
| multipleEditorPages="false", |
| copyrightText="******************************************************************************* |
| Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| All rights reserved. This program and the accompanying materials |
| are made available under the terms of the Eclipse Public License v1.0 |
| which accompanies this distribution, and is available at |
| http://www.eclipse.org/legal/epl-v10.html |
| |
| Contributors: |
| Pierre Allard - initial API and implementation |
| Regent L'Archeveque, |
| Sebastien Gemme |
| |
| SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************", |
| modelName="ApogyCommonMath", |
| suppressGenModelAnnotations="false") |
| @GenModel(dynamicTemplates="true", templateDirectory="platform:/plugin/org.eclipse.apogy.common.emf.codegen/templates") |
| @GenModel(modelDirectory="/org.eclipse.apogy.common.math/src-gen") |
| @GenModel(editDirectory="/org.eclipse.apogy.common.math.edit/src-gen") |
| |
| package org.eclipse.apogy.common.math |
| |
| // Types. |
| |
| import org.eclipse.apogy.common.Apogy |
| |
| type EDoubleArray wraps double[] |
| type Matrix3d wraps javax.vecmath.Matrix3d |
| type Matrix4d wraps javax.vecmath.Matrix4d |
| type VecmathTuple3d wraps javax.vecmath.Tuple3d |
| type Exception wraps Exception |
| |
| /** |
| * A tuple. |
| */ |
| @Apogy(hasCustomClass="true", hasCustomItemProvider="true") |
| class Tuple3d |
| { |
| double x |
| double y |
| double z |
| |
| /** |
| * Returns the Tuple as a javax.vecmath.Tuple3d. |
| * @return A javax.vecmath.Tuple3d with this tuple coordinates. |
| */ |
| op VecmathTuple3d asTuple3d() |
| } |
| |
| /** |
| * A 3 by 3 matrix. |
| */ |
| @Apogy(hasCustomClass="true", hasCustomItemProvider="true") |
| class Matrix3x3 |
| { |
| double m00 = "1.0" |
| double m01 |
| double m02 |
| |
| double m10 |
| double m11 = "1.0" |
| double m12 |
| |
| double m20 |
| double m21 |
| double m22 = "1.0" |
| |
| /** |
| * Returns the Matrix3x3 as a javax.vecmath.Matrix3d. |
| * @return A javax.vecmath.Matrix3d with this matrix elements. |
| */ |
| op Matrix3d asMatrix3d() |
| } |
| |
| |
| /** |
| * A 4 by 4 matrix. |
| */ |
| @Apogy(hasCustomClass="true", hasCustomItemProvider="true") |
| class Matrix4x4 |
| { |
| double m00 = "1.0" |
| double m01 |
| double m02 |
| double m03 |
| |
| double m10 |
| double m11 = "1.0" |
| double m12 |
| double m13 |
| |
| double m20 |
| double m21 |
| double m22 = "1.0" |
| double m23 |
| |
| double m30 |
| double m31 |
| double m32 |
| double m33 = "1.0" |
| |
| /** |
| * Returns the Matrix4x4 as a javax.vecmath.Matrix4d. |
| * @return A javax.vecmath.Matrix4d with this matrix elements. |
| */ |
| op Matrix4d asMatrix4d() |
| } |
| |
| /** |
| * Defines a polynomial equation. |
| * @see https://en.wikipedia.org/wiki/Polynomial |
| */ |
| @Apogy(hasCustomClass="true") |
| class Polynomial |
| { |
| /** |
| * The degree of the polynomial. |
| */ |
| readonly transient volatile int degree = "0" |
| |
| /** |
| * The coefficients of the polynomial, sorted in increasing order. |
| * coeffs[n-1]*x^n-1 + coeffs[n-2]*x^n-2 + ... + coeffs[0]. |
| * |
| * For instance: polynomial 3*x^2 + 5*x + 2, the coefficients would be: |
| * coeffs = { 2, 5, 3 }. |
| */ |
| EDoubleArray coeffs |
| |
| /** |
| * The real roots of the polynomial. |
| */ |
| readonly transient derived EDoubleArray realRoots |
| |
| /** |
| * The imaginary roots of the polynomial. |
| */ |
| readonly transient derived EDoubleArray imaginaryRoots |
| } |
| |
| /** |
| * Facade for Math. |
| */ |
| @Apogy(isSingleton="true", hasCustomClass="true") |
| class ApogyCommonMathFacade |
| { |
| /** |
| * Creates a Matrix4x4 from a javax.vecmath.Matrix4d. |
| * @param matrix The javax.vecmath.Matrix4d. |
| * @return The Matrix4x4 initialized with the matrix elements. |
| */ |
| op Matrix4x4 createMatrix4x4(Matrix4d matrix) |
| |
| /** |
| * Creates a Matrix3x3 from a javax.vecmath.Matrix3d. |
| * @param matrix The javax.vecmath.Matrix3d. |
| * @return The Matrix3x3 initialized with the matrix elements. |
| */ |
| op Matrix3x3 createMatrix3x3(Matrix3d matrix) |
| |
| /** |
| * Creates a Tuple3d from a javax.vecmath.Tuple3d. |
| * @param matrix The javax.vecmath.Tuple3d. |
| * @return The Tuple3d initialized with the tuple coordinates. |
| */ |
| op Tuple3d createTuple3d(VecmathTuple3d tuple) |
| |
| /** |
| * Creates a Tuple3d using 3 coordinates. |
| * @param x The x coordinate value. |
| * @param y The y coordinate value. |
| * @param z The z coordinate value. |
| * @return The Tuple3d initialized with the specified coordinates. |
| */ |
| op Tuple3d createTuple3d(double x , double y , double z) |
| |
| /** |
| * Creates a Polynomial from a list of its coefficients. |
| * @param coeffs The coefficients of the polynomial, sorted in increasing order. |
| * @return The polynomial. |
| */ |
| op Polynomial createPolynomial(EDoubleArray coeffs) |
| |
| /** |
| * Create a Matrix4x4 that is the identity matrix. |
| * @return The Matrix4x4. |
| */ |
| op Matrix4x4 createIdentityMatrix4x4() |
| |
| /** |
| * Create a Matrix3x3 that is the identity matrix. |
| * @return The Matrix3x3. |
| */ |
| op Matrix3x3 createIdentityMatrix3x3() |
| |
| /** |
| * Extract the translation as a Tuple3d from a Matrix4x4 that represents an affine transformation (rotation and translation) in 3D. |
| * @param matrix The affine transformation matrix. |
| * @return The translation as a Tuple3d. |
| */ |
| op Tuple3d extractPosition(Matrix4x4 matrix) |
| |
| /** |
| * Extract the Euler angles as a Tuple3d from a Matrix4x4 that represents an affine transformation (rotation and translation) in 3D. |
| * @param matrix The affine transformation matrix. |
| * @return The Euler angles (Rx, Ry, Rz) as a Tuple3d. Angles are in radians. |
| */ |
| op Tuple3d extractOrientation(Matrix4x4 matrix) |
| } |
| |
| /** |
| * Math Input and Output utilities methods. |
| */ |
| @Apogy(isSingleton="true", hasCustomClass="true") |
| class MathIO |
| { |
| /** |
| * Reads a Matrix4x4 from a file. |
| * @param fileName The absolute path to the file. |
| * @return The Matrix4x4 read from the file in Comma Separated Value format (CSV). |
| * @throws An exception in the read fails. |
| */ |
| op Matrix4x4 readTrMatrix(String fileName) throws Exception |
| |
| /** |
| * Writes a Matrix4x4 from a file in Comma Separated Value format (CSV). |
| * @param trMatrix The matrix to write to file. |
| * @param fileName The absolute path to the file. |
| * @throws An exception in the write fails. |
| */ |
| op void writeTrMatrix(Matrix4x4 trMatrix , String fileName) throws Exception |
| |
| /** |
| * Writes a javax.vecmath.Matrix4d from a file in Comma Separated Value format (CSV). |
| * @param trMatrix The matrix to write to file. |
| * @param fileName The absolute path to the file. |
| * @throws An exception in the write fails. |
| */ |
| op void writeTrMatrix(Matrix4d trMatrix , String fileName) throws Exception |
| } |