예제 #1
0
 // map num from [0, 1emax] to [0, 1]
 public static float exp(int num, int max) {
   int i = 0;
   float ratio = 0;
   for (; i <= max; i++) {
     ratio = (float) (num / Math.pow(10, i));
     if (ratio >= 0 && ratio < 10) break;
   }
   return (float) i / max + 1.0f / max * ratio / 10;
 }
예제 #2
0
  boolean intersect(Ray r, Hit h, Range range) {
    // ToDo:
    boolean retVal = false;
    double Aq = r.getDirection().dot(r.getDirection());
    double Bq =
        2
            * r.getDirection()
                .dot(
                    new Vector3d(
                        r.getOrigin().x - center.x,
                        r.getOrigin().y - center.y,
                        r.getOrigin().z - center.z));
    double Cq =
        (Math.pow(r.getOrigin().x - center.x, 2)
                + Math.pow(r.getOrigin().y - center.y, 2)
                + Math.pow(r.getOrigin().z - center.z, 2))
            - Math.pow(radius, 2);

    double discriminant = Math.pow(Bq, 2) - (4 * Aq * Cq);
    // Hay intersección, si se cumple esta condición... solo se ne
    // necesita el primer valor que es el de la primera intersección
    if (discriminant >= 0) {
      discriminant = Math.sqrt(discriminant);
      double firstT = (-Bq - discriminant) / (2 * Aq);
      if (firstT > range.minT && firstT < range.maxT) {
        h.setColor(this.color);
        range.maxT = firstT;
        h.setT(firstT);
        // se debe retornar T
      }
      retVal = true;
    }
    return retVal;

    // Compute the intersection of the ray with the
    // Sphere and update what needs to be updated
    // Valid values for t must be within the "range"

    // ...
  }
예제 #3
0
  public void interactionForce(Particle other) {
    // ok, now for the fun stuff...
    Vector3d posDif = new Vector3d();
    posDif.sub(x, other.x);

    Vector3d velDif = new Vector3d();
    velDif.sub(v, other.v);

    double d = posDif.length();
    double dSquared = d * d;

    int m = 6;
    int n = 5;
    double r0 = 2 * PARTICLE_RADIUS;
    double cr = r0;
    double cd = r0;
    double b1 = 1;
    double b2 = b1; // *Math.pow(r0, n-m);
    double sumR = 2 * PARTICLE_RADIUS;
    double sr = 250;
    double sd = 70;

    /*sr = dSquared/(cr*cr*(sumR)*(sumR));
    sd = dSquared/(cd*cd*(sumR)*(sumR));

    sr = Math.max(0, 1 - sr);
    sd = Math.max(0, 1 - sd);*/

    Vector3d f = new Vector3d();
    f.set(posDif);
    f.normalize();

    double sf =
        -sr * (b1 / Math.pow(d / r0, m) - b2 / Math.pow(d / r0, n))
            + sd * (velDif.dot(f) / (d / r0));
    f.scale(sf);
    other.f.add(f);
  }
예제 #4
0
 public void power(double exp)
       /* Transforms all the scalar values in 'this' by the rule:
        *   f' = f^exp */
     {
   for (int k = 0; k < size; ++k) f[k] = (float) Math.pow(f[k], exp);
 }