00001 package commandline.ImageStuff.util;
00002
00003 import commandline.ImageStuff.Loc;
00004 import commandline.ImageStuff.Pixel;
00005 import commandline.debuggingCode.Debug;
00006
00007
00008
00009 public class myVector {
00010
00011
00015 private float x;
00019 private float y;
00023 private float z;
00024 public myVector(){
00025 setXYZ(0,0,10);
00026 }
00027
00028 public myVector(Punt_3D begin,Punt_3D eind){
00029 setXYZ(eind.getX()-begin.getX(),eind.getY()-begin.getY(),eind.getZ()-begin.getZ());
00030 }
00031
00032 public void normeer(){
00033 if(this.getX()==0 && this.getY()==0 && this.getZ()==0){
00034 if(!Debug.DISTIBUTION) Debug.print("niet nomeren wegens " + getX()+ " " +getY()+" "+getZ());}
00035 else{
00036 this.multiply(1f/this.norm());
00037 }
00038 }
00039
00040 public myVector(Loc begin,Loc eind){
00041 this((float)(eind.getX()-begin.getX()),(float)(eind.getY()-begin.getY()),0);
00042 }
00043
00044
00045 public myVector(Pixel begin,Pixel eind){
00046 this((float)(eind.getX()-begin.getX()),(float)(eind.getY()-begin.getY()),eind.getZ()-begin.getZ());
00047 }
00048
00049 public myVector(float x, float y, float z) {
00050 setXYZ(x,y,z);
00051 }
00052
00053 public float norm(){
00054 return (float) Math.sqrt(getX()*getX()+getY()*getY()+getZ()*getZ());
00055 }
00056 public void setXYZ(float x, float y, float z){
00057 setX(x);
00058 setY(y);
00059 setZ(z);
00060 }
00061
00062 public void add(myVector v){
00063 setX(getX()+v.getX());
00064 setY(getY()+v.getY());
00065 setZ(getZ()+v.getZ());
00066 }
00067
00068
00069
00070 public void multiply(float alpha){
00071 setX(getX()*alpha);
00072 setY(getY()*alpha);
00073 setZ(getZ()*alpha);
00074 }
00075
00080 public void setX(float x){
00081 this.x=x;
00082 }
00083
00088 public void setY(float y){
00089 this.y=y;
00090 }
00091
00096 public void setZ(float z){
00097 this.z=z;
00098 }
00099
00104 public float getX(){
00105 return this.x;
00106 }
00107
00112 public float getY(){
00113 return this.y;
00114 }
00115
00120 public float getZ(){
00121 return this.z;
00122 }
00123
00124 public myVector vectorieelProduct(myVector v){
00125 float x1= this.getX(); float y1=this.getY(); float z1=this.getZ();
00126 float x2= v.getX(); float y2 = v.getY(); float z2=v.getZ();
00127 return new myVector(y1*z2-z1*y2,-(x1*z2-z1*x2),x1*y2-y1*x2);
00128 }
00129
00130 public float scalair(myVector v){
00131 return getX()*v.getX()+getY()*v.getY()+getZ()*v.getZ();
00132
00133 }
00134
00135 public float rico_met_XY(){
00136 myVector projectie=new myVector(getX(),getY(),0);
00137 double costheta = scalair(projectie)/(projectie.norm()*this.norm());
00138 double theta = Math.acos(costheta);
00139 float rico_normale = (float) Math.tan(theta);
00140 return rico_normale;
00141 }
00142
00143 public myVector getNormale(){
00144 myVector normale= new myVector(-z*x,-z*y ,y*y+x*x);
00145 normale.multiply(1/normale.norm());
00146 return normale;
00147 }
00148
00149
00150 public void print(){
00151 Debug.print(""+this.x);
00152 Debug.print(""+this.y);
00153 Debug.print(""+this.z);
00154 }
00155 }