
Untitled
By: a guest on
Aug 20th, 2012 | syntax:
Java | size: 1.24 KB | hits: 27 | expires: Never
package domain;
import ij.process.ImageProcessor;
public class Sphere extends Transformation {
private int rmax,xC,yC;
private double refindex;
public Sphere(int rmax,double refindex){
this.rmax = rmax;
this.refindex = refindex;
}
public void applyTo ( ImageProcessor ip) {
this.xC = ip.getWidth()/2;
this.yC = ip.getHeight()/2;
super.applyTo(ip);
}
@Override
public Point pointFunction(Point point) {
double dcheck = Math.sqrt(Math.pow(dX(point.x), 2)+Math.pow(dY(point.y), 2));
return calcPix(point.x,point.y,dcheck);
}
public Point calcPix(double x,double y,double dcheck){
double corX,corY;
Point corNew;
if(dcheck<=rmax){
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)))));
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)))));
corNew = new Point(corX,corY);
}else {
corNew = new Point(x,y);
}
return corNew;
}
public double dX(double x){
return x-xC;
}
public double dY(double y){
return y-yC;
}
public double z(double dcheck){
return Math.sqrt(Math.pow(rmax, 2)-Math.pow(dcheck, 2));
}
}