欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

matrix.java

world wind java sdk 源码
JAVA
第 1 页 / 共 4 页
字号:
/* Copyright (C) 2001, 2006 United States Government as represented bythe Administrator of the National Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.geom;import gov.nasa.worldwind.avlist.*;import gov.nasa.worldwind.formats.worldfile.WorldFile;import gov.nasa.worldwind.util.Logging;/** * @author dcollins * @version $Id: Matrix.java 1964 2007-06-08 17:18:56Z dcollins $ */public class Matrix{    public static final Matrix IDENTITY = new Matrix(        1, 0, 0, 0,        0, 1, 0, 0,        0, 0, 1, 0,        0, 0, 0, 1,        true);    // Row 1    public final double m11;    public final double m12;    public final double m13;    public final double m14;    // Row 2    public final double m21;    public final double m22;    public final double m23;    public final double m24;    // Row 3    public final double m31;    public final double m32;    public final double m33;    public final double m34;    // Row 4    public final double m41;    public final double m42;    public final double m43;    public final double m44;    // 16 values in a 4x4 matrix.    private static final int NUM_ELEMENTS = 16;    // True when this matrix represents a 3D transform.    private final boolean isOrthonormalTransform;    // Cached computations.    private int hashCode;    public Matrix(double value)    {        // 'value' is placed in the diagonal.        this(            value, 0, 0, 0,            0, value, 0, 0,            0, 0, value, 0,            0, 0, 0, value);    }    public Matrix(        double m11, double m12, double m13, double m14,        double m21, double m22, double m23, double m24,        double m31, double m32, double m33, double m34,        double m41, double m42, double m43, double m44)    {        this(            m11, m12, m13, m14,            m21, m22, m23, m24,            m31, m32, m33, m34,            m41, m42, m43, m44,            false);    }    Matrix(        double m11, double m12, double m13, double m14,        double m21, double m22, double m23, double m24,        double m31, double m32, double m33, double m34,        double m41, double m42, double m43, double m44,        boolean isOrthonormalTransform)    {        this.m11 = m11;        this.m12 = m12;        this.m13 = m13;        this.m14 = m14;        this.m21 = m21;        this.m22 = m22;        this.m23 = m23;        this.m24 = m24;        this.m31 = m31;        this.m32 = m32;        this.m33 = m33;        this.m34 = m34;        this.m41 = m41;        this.m42 = m42;        this.m43 = m43;        this.m44 = m44;        this.isOrthonormalTransform = isOrthonormalTransform;    }    public final boolean equals(Object obj)    {        if (this == obj)            return true;        if (obj == null || obj.getClass() != this.getClass())            return false;        Matrix that = (Matrix) obj;        return (this.m11 == that.m11) && (this.m12 == that.m12) && (this.m13 == that.m13) && (this.m14 == that.m14)            && (this.m21 == that.m21) && (this.m22 == that.m22) && (this.m23 == that.m23) && (this.m24 == that.m24)            && (this.m31 == that.m31) && (this.m32 == that.m32) && (this.m33 == that.m33) && (this.m34 == that.m34)            && (this.m41 == that.m41) && (this.m42 == that.m42) && (this.m43 == that.m43) && (this.m44 == that.m44);    }    public final int hashCode()    {        if (this.hashCode == 0)        {            int result;            long tmp;            tmp = Double.doubleToLongBits(this.m11);            result = (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m12);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m13);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m14);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m21);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m22);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m23);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m24);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m31);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m32);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m33);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m34);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m41);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m42);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m43);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            tmp = Double.doubleToLongBits(this.m44);            result = 29 * result + (int) (tmp ^ (tmp >>> 32));            this.hashCode = result;        }        return this.hashCode;    }    public static Matrix fromArray(double[] compArray, int offset, boolean rowMajor)    {        if (compArray == null)        {            String msg = Logging.getMessage("nullValue.ArrayIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        if ((compArray.length - offset) < NUM_ELEMENTS)        {            String msg = Logging.getMessage("generic.ArrayInvalidLength", compArray.length);            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }                if (rowMajor)        {            //noinspection PointlessArithmeticExpression            return new Matrix(                // Row 1                compArray[0 + offset],                compArray[1 + offset],                compArray[2 + offset],                compArray[3 + offset],                // Row 2                compArray[4 + offset],                compArray[5 + offset],                compArray[6 + offset],                compArray[7 + offset],                // Row 3                compArray[8 + offset],                compArray[9 + offset],                compArray[10 + offset],                compArray[11 + offset],                // Row 4                compArray[12 + offset],                compArray[13 + offset],                compArray[14 + offset],                compArray[15 + offset]);        }        else        {            //noinspection PointlessArithmeticExpression            return new Matrix(                // Row 1                compArray[0 + offset],                compArray[4 + offset],                compArray[8 + offset],                compArray[12 + offset],                // Row 2                compArray[1 + offset],                compArray[5 + offset],                compArray[9 + offset],                compArray[13 + offset],                // Row 3                compArray[2 + offset],                compArray[6 + offset],                compArray[10 + offset],                compArray[14 + offset],                // Row 4                compArray[3 + offset],                compArray[7 + offset],                compArray[11 + offset],                compArray[15 + offset]);        }    }    public final double[] toArray(double[] compArray, int offset, boolean rowMajor)    {        if (compArray == null)        {            String msg = Logging.getMessage("nullValue.ArrayIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        if ((compArray.length - offset) < NUM_ELEMENTS)        {            String msg = Logging.getMessage("generic.ArrayInvalidLength", compArray.length);            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        if (rowMajor)        {            // Row 1            //noinspection PointlessArithmeticExpression            compArray[0 + offset] = this.m11;            compArray[1 + offset] = this.m12;            compArray[2 + offset] = this.m13;            compArray[3 + offset] = this.m14;            // Row 2            compArray[4 + offset] = this.m21;            compArray[5 + offset] = this.m22;            compArray[6 + offset] = this.m23;            compArray[7 + offset] = this.m24;            // Row 3            compArray[8 + offset] = this.m31;            compArray[9 + offset] = this.m32;            compArray[10 + offset] = this.m33;            compArray[11 + offset] = this.m34;            // Row 4            compArray[12 + offset] = this.m41;            compArray[13 + offset] = this.m42;            compArray[14 + offset] = this.m43;            compArray[15 + offset] = this.m44;        }        else        {            // Row 1            //noinspection PointlessArithmeticExpression            compArray[0 + offset] = this.m11;            compArray[4 + offset] = this.m12;            compArray[8 + offset] = this.m13;            compArray[12 + offset] = this.m14;            // Row 2            compArray[1 + offset] = this.m21;            compArray[5 + offset] = this.m22;            compArray[9 + offset] = this.m23;            compArray[13 + offset] = this.m24;            // Row 3            compArray[2 + offset] = this.m31;            compArray[6 + offset] = this.m32;            compArray[10 + offset] = this.m33;            compArray[14 + offset] = this.m34;            // Row 4            compArray[3 + offset] = this.m41;            compArray[7 + offset] = this.m42;            compArray[11 + offset] = this.m43;            compArray[15 + offset] = this.m44;        }        return compArray;    }    public final String toString()    {        StringBuilder sb = new StringBuilder();        sb.append("(");        sb.append(this.m11).append(", ").append(this.m12).append(", ").append(this.m13).append(", ").append(this.m14);        sb.append(", \r\n");        sb.append(this.m21).append(", ").append(this.m22).append(", ").append(this.m23).append(", ").append(this.m24);        sb.append(", \r\n");        sb.append(this.m31).append(", ").append(this.m32).append(", ").append(this.m33).append(", ").append(this.m34);        sb.append(", \r\n");        sb.append(this.m41).append(", ").append(this.m42).append(", ").append(this.m43).append(", ").append(this.m44);        sb.append(")");        return sb.toString();    }    public final double getM11()    {        return this.m11;    }    public final double getM12()    {        return this.m12;    }    public final double getM13()    {        return this.m13;    }    public final double getM14()    {        return this.m14;    }    public final double getM21()    {        return this.m21;    }    public final double getM22()    {        return this.m22;    }    public final double getM23()    {        return this.m23;    }    public final double getM24()    {        return this.m24;    }    public final double getM31()    {        return this.m31;    }    public final double getM32()    {        return this.m32;    }    public final double getM33()    {        return this.m33;    }    public final double getM34()    {        return this.m34;    }    public final double getM41()    {        return this.m41;    }    public final double getM42()    {        return this.m42;    }    public final double getM43()    {        return this.m43;    }    public final double getM44()    {        return this.m44;    }    public final double m11()    {        return this.m11;    }    public final double m12()    {        return this.m12;    }    public final double m13()    {        return this.m13;    }    public final double m14()    {        return this.m14;    }    public final double m21()    {        return this.m21;    }    public final double m22()    {        return this.m22;    }    public final double m23()    {        return this.m23;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -