Package raytracer.common.object

Source Code of raytracer.common.object.Cylinder

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());
  }

}
TOP

Related Classes of raytracer.common.object.Cylinder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.