Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 20th, 2012  |  syntax: Java  |  size: 1.24 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package domain;
  2.  
  3. import ij.process.ImageProcessor;
  4.  
  5. public class Sphere extends Transformation {
  6.  
  7.         private int rmax,xC,yC;
  8.         private double refindex;
  9.        
  10.         public Sphere(int rmax,double refindex){
  11.                 this.rmax = rmax;
  12.                 this.refindex = refindex;
  13.         }
  14.        
  15.         public void applyTo ( ImageProcessor ip) {
  16.                 this.xC = ip.getWidth()/2;
  17.                 this.yC = ip.getHeight()/2;
  18.                 super.applyTo(ip);
  19.         }
  20.         @Override
  21.         public Point pointFunction(Point point) {
  22.                 double dcheck = Math.sqrt(Math.pow(dX(point.x), 2)+Math.pow(dY(point.y), 2));
  23.                 return calcPix(point.x,point.y,dcheck);
  24.         }
  25.        
  26.         public Point calcPix(double x,double y,double dcheck){
  27.                 double corX,corY;
  28.                 Point corNew;
  29.                 if(dcheck<=rmax){
  30.                         corX = x-z(dcheck)*Math.tan((1-(1/refindex))*Math.asin(dX(x)/(Math.sqrt(Math.pow(dX(x), 2)+Math.pow(z(dcheck), 2)))));
  31.                         corY = y-z(dcheck)*Math.tan((1-(1/refindex))*Math.asin(dY(y)/(Math.sqrt(Math.pow(dY(y), 2)+Math.pow(z(dcheck), 2)))));
  32.                         corNew = new Point(corX,corY);
  33.                 }else {
  34.                         corNew = new Point(x,y);
  35.                 }
  36.                
  37.                 return corNew;
  38.         }
  39.         public double dX(double x){
  40.                 return x-xC;
  41.                
  42.         }
  43.        
  44.         public double dY(double y){
  45.                 return y-yC;
  46.                
  47.         }
  48.         public double z(double dcheck){
  49.                 return Math.sqrt(Math.pow(rmax, 2)-Math.pow(dcheck, 2));
  50.                
  51.         }
  52.  
  53.  
  54. }