ArViewer  Android Version
Arvos - Augmented reality viewer open source
 All Classes Namespaces Files Functions Variables
Vector.java
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Gregory Beauchamp
3  *
4  * Derived from
5  * http://android-raypick.blogspot.com/2012/04/first-i-want-to-state-this-is-my-first.html
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 package com.mission_base.arviewer_android.viewer.utilities;
21 
22 public class Vector {
23  // dot product (3D) which allows vector operations in arguments
24  public static float dot(float[] u,float[] v) {
25  return ((u[X] * v[X]) + (u[Y] * v[Y]) + (u[Z] * v[Z]));
26  }
27  public static float[] minus(float[] u, float[] v){
28  return new float[]{u[X]-v[X],u[Y]-v[Y],u[Z]-v[Z]};
29  }
30  public static float[] addition(float[] u, float[] v){
31  return new float[]{u[X]+v[X],u[Y]+v[Y],u[Z]+v[Z]};
32  }
33  //scalar product
34  public static float[] scalarProduct(float r, float[] u){
35  return new float[]{u[X]*r,u[Y]*r,u[Z]*r};
36  }
37  // (cross product)
38  public static float[] crossProduct(float[] u, float[] v){
39  return new float[]{(u[Y]*v[Z]) - (u[Z]*v[Y]),(u[Z]*v[X]) - (u[X]*v[Z]),(u[X]*v[Y]) - (u[Y]*v[X])};
40  }
41  //magnitude or length
42  public static float length(float[] u){
43  return (float) Math.abs(Math.sqrt((u[X] *u[X]) + (u[Y] *u[Y]) + (u[Z] *u[Z])));
44  }
45 
46  public static final int X = 0;
47  public static final int Y = 1;
48  public static final int Z = 2;
49 }