Android Open Source - Thrift-box Vector3






From Project

Back to project page Thrift-box.

License

The source code is released under:

GNU General Public License

If you think the Android project Thrift-box listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.mikephil.charting.matrix;
//from  w  w  w  .j a  v a  2 s .  c  om
/**
 * Simple 3D vector class. Handles basic vector math for 3D vectors.
 */
public final class Vector3 {
    public float x;
    public float y;
    public float z;

    public static final Vector3 ZERO = new Vector3(0, 0, 0);
    public static final Vector3 UNIT_X = new Vector3(1, 0, 0);
    public static final Vector3 UNIT_Y = new Vector3(0, 1, 0);
    public static final Vector3 UNIT_Z = new Vector3(0, 0, 1);

    public Vector3() {
    }

    public Vector3(float[] array)
    {
        set(array[0], array[1], array[2]);
    }

    public Vector3(float xValue, float yValue, float zValue) {
        set(xValue, yValue, zValue);
    }

    public Vector3(Vector3 other) {
        set(other);
    }

    public final void add(Vector3 other) {
        x += other.x;
        y += other.y;
        z += other.z;
    }

    public final void add(float otherX, float otherY, float otherZ) {
        x += otherX;
        y += otherY;
        z += otherZ;
    }

    public final void subtract(Vector3 other) {
        x -= other.x;
        y -= other.y;
        z -= other.z;
    }

    public final void subtractMultiple(Vector3 other, float multiplicator)
    {
        x -= other.x * multiplicator;
        y -= other.y * multiplicator;
        z -= other.z * multiplicator;
    }

    public final void multiply(float magnitude) {
        x *= magnitude;
        y *= magnitude;
        z *= magnitude;
    }

    public final void multiply(Vector3 other) {
        x *= other.x;
        y *= other.y;
        z *= other.z;
    }

    public final void divide(float magnitude) {
        if (magnitude != 0.0f) {
            x /= magnitude;
            y /= magnitude;
            z /= magnitude;
        }
    }

    public final void set(Vector3 other) {
        x = other.x;
        y = other.y;
        z = other.z;
    }

    public final void set(float xValue, float yValue, float zValue) {
        x = xValue;
        y = yValue;
        z = zValue;
    }

    public final float dot(Vector3 other) {
        return (x * other.x) + (y * other.y) + (z * other.z);
    }

    public final Vector3 cross(Vector3 other) {
        return new Vector3(y * other.z - z * other.y,
                z * other.x - x * other.z,
                x * other.y - y * other.x);
    }

    public final float length() {
        return (float) Math.sqrt(length2());
    }

    public final float length2() {
        return (x * x) + (y * y) + (z * z);
    }

    public final float distance2(Vector3 other) {
        float dx = x - other.x;
        float dy = y - other.y;
        float dz = z - other.z;
        return (dx * dx) + (dy * dy) + (dz * dz);
    }

    public final float normalize() {
        final float magnitude = length();

        // TODO: I'm choosing safety over speed here.
        if (magnitude != 0.0f) {
            x /= magnitude;
            y /= magnitude;
            z /= magnitude;
        }

        return magnitude;
    }

    public final void zero() {
        set(0.0f, 0.0f, 0.0f);
    }

    public final boolean pointsInSameDirection(Vector3 other) {
        return this.dot(other) > 0;
    }

}




Java Source Code List

android.support.v4.preference.PreferenceFragment.java
android.support.v4.preference.PreferenceManagerCompat.java
android.widget_fixed.CursorFilter.java
android.widget_fixed.CursorTreeAdapter.java
com.github.mikephil.charting.charts.Chart.java
com.github.mikephil.charting.charts.PieChart.java
com.github.mikephil.charting.charts.PieRadarChartBase.java
com.github.mikephil.charting.data.ChartData.java
com.github.mikephil.charting.data.DataSet.java
com.github.mikephil.charting.data.Entry.java
com.github.mikephil.charting.data.PieDataSet.java
com.github.mikephil.charting.data.PieData.java
com.github.mikephil.charting.data.filter.Approximator.java
com.github.mikephil.charting.exception.DrawingDataSetNotCreatedException.java
com.github.mikephil.charting.interfaces.ChartInterface.java
com.github.mikephil.charting.interfaces.OnChartGestureListener.java
com.github.mikephil.charting.interfaces.OnChartValueSelectedListener.java
com.github.mikephil.charting.interfaces.OnDrawLineChartTouchListener.java
com.github.mikephil.charting.interfaces.OnDrawListener.java
com.github.mikephil.charting.listener.PieRadarChartTouchListener.java
com.github.mikephil.charting.matrix.Vector3.java
com.github.mikephil.charting.renderer.Transformer.java
com.github.mikephil.charting.utils.ColorFormatter.java
com.github.mikephil.charting.utils.ColorTemplate.java
com.github.mikephil.charting.utils.Highlight.java
com.github.mikephil.charting.utils.LabelBase.java
com.github.mikephil.charting.utils.LargeValueFormatter.java
com.github.mikephil.charting.utils.Legend.java
com.github.mikephil.charting.utils.LimitLine.java
com.github.mikephil.charting.utils.MarkerView.java
com.github.mikephil.charting.utils.PointD.java
com.github.mikephil.charting.utils.SelInfo.java
com.github.mikephil.charting.utils.Utils.java
com.github.mikephil.charting.utils.ValueFormatter.java
com.github.mikephil.charting.utils.XLabels.java
com.github.mikephil.charting.utils.YLabels.java
net.margaritov.preference.colorpicker.AlphaPatternDrawable.java
net.margaritov.preference.colorpicker.ColorPickerDialog.java
net.margaritov.preference.colorpicker.ColorPickerPanelView.java
net.margaritov.preference.colorpicker.ColorPickerPreference.java
net.margaritov.preference.colorpicker.ColorPickerView.java
ru.sash0k.thriftbox.AdapterExpenses.java
ru.sash0k.thriftbox.MainActivity.java
ru.sash0k.thriftbox.TypefaceSpan2.java
ru.sash0k.thriftbox.Utils.java
ru.sash0k.thriftbox.Widget.java
ru.sash0k.thriftbox.categories.Categories.java
ru.sash0k.thriftbox.categories.InterceptingHorizontalScrollView.java
ru.sash0k.thriftbox.database.DBProvider.java
ru.sash0k.thriftbox.database.DB.java
ru.sash0k.thriftbox.fragments.CommentDialog.java
ru.sash0k.thriftbox.fragments.DeleteConfirmDialog.java
ru.sash0k.thriftbox.fragments.ExpandableListFragment.java
ru.sash0k.thriftbox.fragments.ExpensesFragment.java
ru.sash0k.thriftbox.fragments.InputFragment.java
ru.sash0k.thriftbox.fragments.PieChartFragment.java
ru.sash0k.thriftbox.fragments.SettingsFragment.java