All Downloads are FREE. Search and download functionalities are using the official Maven repository.

one.empty3.library.Matrix33 Maven / Gradle / Ivy

There is a newer version: 2024.5.10
Show newest version
/*
 * Copyright (c) 2023. Manuel Daniel Dahmen
 *
 *
 *    Copyright 2012-2023 Manuel Daniel Dahmen
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

/*

 Vous êtes libre de :

 */
package one.empty3.library;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/*__
 * @author MANUEL DAHMEN
 *         

* dev *

* 17 nov. 2011 */ public class Matrix33 extends Representable { public static final Matrix33 XYZ; public static final Matrix33 YZX; public static final Matrix33 ZXY; public static final Matrix33 I; public static final Matrix33 O; static { O = new Matrix33(new Double[]{0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d}); XYZ = new Matrix33(new Double[]{1d, 0d, 0d, 0d, 1d, 0d, 0d, 0d, 1d}); YZX = new Matrix33(new Double[]{0d, 1d, 0d, 0d, 0d, 1d, 1d, 0d, 0d}); ZXY = new Matrix33(new Double[]{0d, 0d, 1d, 1d, 0d, 0d, 0d, 1d, 0d}); I = new Matrix33(new Double[]{1d, 0d, 0d, 0d, 1d, 0d, 0d, 0d, 1d}); } private StructureMatrix d = new StructureMatrix<>(1, Double.class); private int dim1; private int dim2; public Matrix33(Matrix33 copy) { this(); d.setAll(copy.getDoubleArray1e()); } public Matrix33() { d = new StructureMatrix<>(1, Double.class); d.setAll(new Double[]{1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}); dim1 = dim2 = (int) Math.sqrt(d.getData1d().size()); } public Matrix33(Double[] d) { dim1 = dim2 = (int) Math.sqrt(d.length); if (d.length != 9) { Logger.getAnonymousLogger().log(Level.INFO, "Erreur dans Matrix33 . 9 éléments requis"); throw new IndexOutOfBoundsException("Matrix33 9 " + d.length); } for (int i = 0; i < d.length; i++) { d[i] = d[i]==null?0.0:d[i]; } this.d.setAll(d); } public Matrix33(double[] d) { if (d.length != 9) { Logger.getAnonymousLogger().log(Level.INFO, "Erreur dans Matrix33 . 9 éléments requis"); throw new IndexOutOfBoundsException("Matrix33 9 " + d.length); } dim1 = dim2 = (int) Math.sqrt(d.length); Double[] D = new Double[9]; for (int i = 0; i < d.length; i++) { d[i] = d[i]; } this.d.setAll(D); } public Matrix33(Point3D[] p) { this(); for (int i = 0; i < 3; i++) { if(p[i]==null) p[i] = Point3D.O0; for (int j = 0; j < 3; j++) { if(p[i].get(j)==null) p[i].set(j, 0.0); d.setElem(p[i].get(j), i * 3 + j); } } dim1 = dim2 = (int) Math.sqrt(p.length); } public Matrix33(int columns, int lines) { for(int i=0; i 1) { a = this; for (int i = 2; i <= n; i++) a = a.mult(this); } else if (n == -1) { a = inverse(); } else if (n < -1) { a = inverse(); for (int i = -1; i >= n; i--) a = a.mult(this); } return new Matrix33(a); } public Matrix33 pourcents(Matrix33 m, double pc) { return mult(1 - pc).plus(m.mult(pc)); } public List getDoubles() { return d.getData1d(); } @Override public void declareProperties() { super.declareProperties(); getDeclaredDataStructure().put("d/3x3 matrix", d); } public StructureMatrix getD() { return d; } public void setD(Double[] d1) { d = new StructureMatrix<>(1, Double.class); d.setAll(d1); } public Point3D[] getColVectors() { Point3D[] colVectors = new Point3D[3]; for (int c = 0; c < 3; c++) { Point3D p = new Point3D(d.getElem(c), d.getElem(3 + c), d.getElem(6 + c)); colVectors[c] = p; } return colVectors; } public Point3D[] getRowVectors() { Point3D[] rowVectors = new Point3D[3]; for (int l = 0; l < 3; l++) { Point3D p = new Point3D(d.getElem(l * 3), d.getElem(l * 3 + 1), d.getElem(l * 3 + 2)); rowVectors[l] = p; } return rowVectors; } public double determinant() { double det = 0.0; for(int i=0; i





© 2015 - 2024 Weber Informatics LLC | Privacy Policy