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