Package ca.eandb.jmist.math

Examples of ca.eandb.jmist.math.Point3


   */
  public Sphere boundingSphere() {

    double  h = this.height / 2.0;
    double  r = Math.sqrt(this.radius * this.radius + h * h);
    Point3  c = new Point3(this.base.x(), this.base.y() + h, this.base.z());

    return new Sphere(c, r);

  }
View Full Code Here


    case CYLINDER_SURFACE_TOP:
      return Vector3.J;

    case CYLINDER_SURFACE_BODY:
      Point3 p = x.getPosition();
      return new Vector3(p.x() - this.base.x(), 0.0, p.z()
          - this.base.z()).unit();

    default:
      throw new IllegalArgumentException("Invalid surface ID.");
View Full Code Here

    }
  };

  private EvaluateResult evaluate(Ray3 ray, double t) {

    Point3  p = ray.pointAt(t);
    Vector3  d = ray.direction();
    double  X2e_1 = Math.pow(Math.abs(p.x()), 2.0 / e - 1.0);
    double  Y2e_1 = Math.pow(Math.abs(p.y()), 2.0 / e - 1.0);
    double  Z2n_1 = Math.pow(Math.abs(p.z()), 2.0 / n - 1.0);
    double  X2e = Math.abs(p.x()) * X2e_1;
    double  Y2e = Math.abs(p.y()) * Y2e_1;
    double  Z2n = Math.abs(p.z()) * Z2n_1;
    double  A_1 = Math.pow(X2e + Y2e, e / n - 1.0);
    double  A = (X2e + Y2e) * A_1;

    return new EvaluateResult(
        A + Z2n - 1.0,
        (2.0 / n)
        * (A_1
            * (X2e_1 * d.x() * Math.signum(p.x()) + Y2e_1 * d.y()
                * Math.signum(p.y())) + Z2n_1 * d.z()
            * Math.signum(p.z()))
    );

  }
View Full Code Here

  }

  private double findRoot(Ray3 ray, double a, double b) {

    Point3  pa = ray.pointAt(a), pb = ray.pointAt(b);
    double  va = evaluate(pa), vb = evaluate(pb);

    if (Math.abs(va) < SUPERELLIPSOID_TOLERANCE)
      return a;

    if (Math.abs(vb) < SUPERELLIPSOID_TOLERANCE)
      return b;

    for (int i = 0; i < SUPERELLIPSOID_MAX_ITERATIONS; i++) {
      double  t0, t1, vt0, vt1;
      Point3  pt0, pt1;

      assert(va * vb < 0.0);

      double  m = (0.0 - va) / (vb - va);
      assert(MathUtil.inRangeOO(m, 0.0, 1.0));
View Full Code Here

   * @see ca.eandb.jmist.framework.AbstractGeometry#getNormal(ca.eandb.jmist.framework.AbstractGeometry.GeometryIntersection)
   */
  @Override
  protected Vector3 getNormal(GeometryIntersection x) {

    Point3  p = x.getPosition();
    double  A = Math.pow(Math.pow(Math.abs(p.x()), 2.0 / e) + Math.pow(Math.abs(p.y()), 2.0 / e), e / n - 1.0);
    double  X = A * Math.pow(Math.abs(p.x()), 2.0 / e - 1.0);
    double  Y = A * Math.pow(Math.abs(p.y()), 2.0 / e - 1.0);
    double  Z = Math.pow(Math.abs(p.z()), 2.0 / n - 1.0);

    return new Vector3(
      Math.signum(p.x()) * X,
      Math.signum(p.y()) * Y,
      Math.signum(p.z()) * Z
    ).unit();

  }
View Full Code Here

    double t = this.plane.intersect(ray);

    if (recorder.interval().contains(t)) {

      Point3 p = ray.pointAt(t);

      if (this.boundingSphere.contains(p)) {

        GeometryIntersection x = super.newIntersection(ray, t, true, fromTop ? DISC_SURFACE_TOP : DISC_SURFACE_BOTTOM)
          .setLocation(p);
View Full Code Here

    double r = this.boundingSphere.radius();
    double ri = r * Math.hypot(u.x(), v.x());
    double rj = r * Math.hypot(u.y(), v.y());
    double rk = r * Math.hypot(u.z(), v.z());

    Point3 c = this.boundingSphere.center();

    return new Box3(
        c.x() - ri,
        c.y() - rj,
        c.z() - rk,
        c.x() + ri,
        c.y() + rj,
        c.z() + rk
        );

  }
View Full Code Here

  @Override
  public void generateRandomSurfacePoint(ShadingContext context, double ru, double rv, double rj) {
    Vector2 uv = RandomUtil.uniformOnDisc(boundingSphere.radius(), ru, rv).toCartesian();
    Basis3 basis = Basis3.fromW(this.plane.normal(), Basis3.Orientation.RIGHT_HANDED);

    Point3 p = boundingSphere.center()
        .plus(basis.u().times(uv.x()))
        .plus(basis.v().times(uv.y()));

    int id = (twoSided && RandomUtil.coin(rj))
        ? DISC_SURFACE_BOTTOM
View Full Code Here

       */
      public boolean visit(Ray3 ray, Interval I, Cell cell) {

        /* Get the points at which the ray enters and exits the cell.
         */
        Point3 p0 = ray.pointAt(I.minimum());
        Point3 p1 = ray.pointAt(I.maximum());

        /* Get the range of y-values for the ray within the cell, and
         * get the portion of the height matrix within the cell.
         */
        Interval h = Interval.between(p0.y(), p1.y());
        Matrix slice = height.slice(cell.getX(), cell.getZ(), 2, 2);

        boolean hit = false;

        /* If the range of y-values intersect, then there may be an
         * intersection.
         */
        if (h.intersects(slice.range())) {

          Box3 bounds = cell.getBoundingBox();

          /* Get the points on the height field. */
          Point3 p00 = new Point3(bounds.minimumX(), slice.at(0, 0), bounds.minimumZ());
          Point3 p01 = new Point3(bounds.minimumX(), slice.at(0, 1), bounds.maximumZ());
          Point3 p10 = new Point3(bounds.maximumX(), slice.at(1, 0), bounds.minimumZ());
          Point3 p11 = new Point3(bounds.maximumX(), slice.at(1, 1), bounds.maximumZ());

          Plane3 plane;
          double t;

          /* Divide the four points into two triangles and check for
           * an intersection with each triangle.
           */
          plane = Plane3.throughPoints(p00, p10, p11);
          t = plane.intersect(ray);

          if (I.contains(t)) {
            Point3 p = ray.pointAt(t);

            /* Get the normalized (x,z) coordinates, (cx, cz),
             * within the bounds of the cell.  If cx > cz, then
             * the intersection hit the triangle, otherwise, it hit
             * the plane, but on the other half of the cell.
             */
            double cx = (p.x() - p00.x()) / (p10.x() - p00.x());
            double cz = (p.z() - p10.z()) / (p11.z() - p10.z());

            if (cx > cz) {
              Intersection x = newIntersection(ray, t, ray.direction().dot(plane.normal()) < 0.0)
                .setBasis(Basis3.fromW(plane.normal(), Basis3.Orientation.RIGHT_HANDED))
                .setLocation(p);

              recorder.record(x);

              hit = true;
            }
          }

          plane = Plane3.throughPoints(p00, p11, p01);
          t = plane.intersect(ray);

          if (I.contains(t)) {
            Point3 p = ray.pointAt(t);

            /* Get the normalized (x,z) coordinates, (cx, cz),
             * within the bounds of the cell.  If cx < cz, then
             * the intersection hit the triangle, otherwise, it hit
             * the plane, but on the other half of the cell.
             */
            double cx = (p.x() - p00.x()) / (p10.x() - p00.x());
            double cz = (p.z() - p10.z()) / (p11.z() - p10.z());

            if (cx < cz) {
              Intersection x = newIntersection(ray, t, ray.direction().dot(plane.normal()) < 0.0)
                .setBasis(Basis3.fromW(plane.normal(), Basis3.Orientation.RIGHT_HANDED))
                .setLocation(p);
View Full Code Here

  /* (non-Javadoc)
   * @see ca.eandb.jmist.framework.AbstractGeometry#getTextureCoordinates(ca.eandb.jmist.framework.AbstractGeometry.GeometryIntersection)
   */
  @Override
  protected Point2 getTextureCoordinates(GeometryIntersection x) {
    Point3 p = x.getPosition();
    Box3 bounds = grid.getBoundingBox();
    return new Point2(
        (p.x() - bounds.minimumX()) / (bounds.maximumX() - bounds.minimumX()),
        (p.z() - bounds.minimumZ()) / (bounds.maximumZ() - bounds.minimumZ())
    );
  }
View Full Code Here

TOP

Related Classes of ca.eandb.jmist.math.Point3

Copyright © 2018 www.massapicom. 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.