package raytracer.common.object;
import raytracer.common.type.Ray;
import raytracer.common.type.Vector;
import raytracer.common.util.Solver;
public class Cylinder extends RtObject{
private double rayon;
@Override
public double[] primitive(Ray ray) {
double coef[] = new double[3];
Vector ori = ray.getOrigin().transformation(this.center, this.rotation);
Vector dir = ray.getDirection().transformation(null, this.rotation);
coef[0] = dir.getX() * dir.getX() + dir.getY() * dir.getY();
coef[1] = 2. * (dir.getX() * ori.getX() + dir.getY() * ori.getY());
coef[2] = ori.getX() * ori.getX() + ori.getY() * ori.getY() - rayon * rayon;
return (Solver.deg2(coef));
}
@Override
public Vector normal(Vector inter) {
Vector tmp = inter.transformation(this.center, this.rotation);
tmp.setZ(0);
return (tmp.reverseRotation(this.rotation).normal());
}
}