Ejemplo n.º 1
0
    protected void render(DrawContext dc, Vec4 p1, Vec4 p2, double radius) {
      // To compute the rotation of the cylinder axis to the orientation of the vector between the
      // two points,
      // this method performs the same operation as Vec4.axisAngle() but with a "v2" of <0, 0, 1>.

      // Compute rotation angle
      double length = p1.distanceTo3(p2);
      Vec4 u1 = new Vec4((p2.x - p1.x) / length, (p2.y - p1.y) / length, (p2.z - p1.z) / length);
      double angle = Math.acos(u1.z);

      // Compute the direction cosine factors that define the rotation axis
      double A = -u1.y;
      double B = u1.x;
      double L = Math.sqrt(A * A + B * B);

      GL gl = dc.getGL();

      // pushReferenceCenter performs the translation of the pipe's origin to point p1 and the
      // necessary
      // push/pop of the modelview stack. Otherwise we'd need to include a glPushMatrix and
      // gl.glTranslated(p1.x, p1.y, p1.z) above the rotation, and a corresponding glPopMatrix after
      // the
      // call to glCallIst.
      dc.getView().pushReferenceCenter(dc, p1);
      gl.glRotated(angle * TO_DEGREES, A / L, B / L, 0);
      gl.glScaled(
          radius, radius, length / 2); // length / 2 because cylinder is created with length 2
      dc.getGL().glCallList(this.glListId);
      dc.getView().popReferenceCenter(dc);
    }
  // calculates the angle between two vectors
  // i.e. θ = arccos(A•B / |A||B|)
  void angle(Vector vector) {
    double maga = this.magnitude();
    double magb = vector.magnitude();
    double mag = maga * magb;
    double dot = this.dotProduct(vector);

    double angle = Math.acos(dot / mag);
    System.out.printf("\nAngle: %.3f\n", angle);
  }
Ejemplo n.º 3
0
 public static double distance(double lat1, double lon1, double lat2, double lon2) {
   double theta = lon1 - lon2;
   double dist =
       Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
           + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
   dist = Math.acos(dist);
   dist = rad2deg(dist);
   dist = dist * 60 * 1.85315962;
   return (dist);
 }
Ejemplo n.º 4
0
 static double gcDistance(double pLat, double pLong, double qLat, double qLong, double radius) {
   pLat *= Math.PI / 180;
   pLong *= Math.PI / 180;
   qLat *= Math.PI / 180;
   qLong *= Math.PI / 180;
   return radius
       * Math.acos(
           Math.cos(pLat) * Math.cos(pLong) * Math.cos(qLat) * Math.cos(qLong)
               + Math.cos(pLat) * Math.sin(pLong) * Math.cos(qLat) * Math.sin(qLong)
               + Math.sin(pLat) * Math.sin(qLat));
 }
Ejemplo n.º 5
0
 static long gcDistance(double pLat, double pLong, double qLat, double qLong, double radius) {
   pLat *= PI / 180;
   pLong *= PI / 180;
   qLat *= PI / 180;
   qLong *= PI / 180;
   return Math.round(
       radius
           * Math.acos(
               Math.cos(pLat) * Math.cos(pLong) * Math.cos(qLat) * Math.cos(qLong)
                   + Math.cos(pLat) * Math.sin(pLong) * Math.cos(qLat) * Math.sin(qLong)
                   + Math.sin(pLat) * Math.sin(qLat)));
 }
Ejemplo n.º 6
0
  private int getEnvironmentMap(Vector3f normal, int[] inPixels, int width, int height) {
    if (environmentMap != null) {
      float angle = (float) Math.acos(-normal.y);

      float x, y;
      y = angle / ImageMath.PI;

      if (y == 0.0f || y == 1.0f) x = 0.0f;
      else {
        float f = normal.x / (float) Math.sin(angle);

        if (f > 1.0f) f = 1.0f;
        else if (f < -1.0f) f = -1.0f;

        x = (float) Math.acos(f) / ImageMath.PI;
      }
      // A bit of empirical scaling....
      x = ImageMath.clamp(x * envWidth, 0, envWidth - 1);
      y = ImageMath.clamp(y * envHeight, 0, envHeight - 1);
      int ix = (int) x;
      int iy = (int) y;

      float xWeight = x - ix;
      float yWeight = y - iy;
      int i = envWidth * iy + ix;
      int dx = ix == envWidth - 1 ? 0 : 1;
      int dy = iy == envHeight - 1 ? 0 : envWidth;
      return ImageMath.bilinearInterpolate(
          xWeight,
          yWeight,
          envPixels[i],
          envPixels[i + dx],
          envPixels[i + dy],
          envPixels[i + dx + dy]);
    }
    return 0;
  }
Ejemplo n.º 7
0
    public void update() {
      Vector2D prevVector = main.getPosition().subtract(previous.getPosition());
      Vector2D nextVector = next.getPosition().subtract(main.getPosition());

      double angleRad =
          Math.acos(prevVector.dot(nextVector) / (prevVector.norm() * nextVector.norm()));
      double angle = Math.toDegrees(angleRad);
      if (prevVector.crossMag(nextVector) > 0) {
        angle = 360.0 - angle;
      }

      double forceMag = ANGLE_CONSTANT * (angle - 90.0);

      forces.put(previous, prevVector.rotate270().scaleTo(NEIGHBOR_ANGLE_SCALE * forceMag));
      forces.put(main, normals.get(main).scaleTo(forceMag));
      forces.put(next, nextVector.rotate270().scaleTo(NEIGHBOR_ANGLE_SCALE * forceMag));
    }
Ejemplo n.º 8
0
public class Main implements Runnable {

  final String filename = "in";

  public static void main(String[] args) {
    // new Thread(new Main()).start();
    new Thread(null, new Main(), "1", 1 << 25).start();
  }

  public void run() {
    try {
      // in = new BufferedReader(new InputStreamReader(System.in));
      out = new BufferedWriter(new OutputStreamWriter(System.out));
      in = new BufferedReader(new FileReader(filename + ".in"));
      // out = new BufferedWriter(new FileWriter(filename+".out"));
      int kase = iread();
      for (int i = 1; i <= kase; ++i) {
        // TODO CODE HERE
        solve1216(i);
      }
      out.flush();
    } catch (Exception e) {
      System.exit(1);
    }
  }

  final double pii = ((double) (2.)) * Math.acos(0);

  public void solve1216(int kaseno) throws Exception {
    int r1 = iread(), r2 = iread(), h = iread(), p = iread();

    double R1 = (double) r2;
    double R2 = ((double) ((r1 - r2) * p)) / h;
    R2 += r2;
    double H = (double) p;

    double ret = pii * (R1 * R1 + R2 * R2 + R1 * R2) * H;
    ret /= 3.;
    Format df = new DecimalFormat("0.0000000000");
    String res = df.format(ret);
    out.write("Case " + kaseno + ": " + res + "\n");
  }

  public void debug(Object... o) {
    System.err.println(Arrays.deepToString(o));
  }

  public int iread() throws Exception {
    return Integer.parseInt(readword());
  }

  public double dread() throws Exception {
    return Double.parseDouble(readword());
  }

  public long lread() throws Exception {
    return Long.parseLong(readword());
  }

  BufferedReader in;
  BufferedWriter out;

  public String readword() throws IOException {
    StringBuilder b = new StringBuilder();
    int c;
    c = in.read();
    while (c >= 0 && c <= ' ') {
      c = in.read();
    }
    if (c < 0) {
      return "";
    }
    while (c > ' ') {
      b.append((char) c);
      c = in.read();
    }
    return b.toString();
  }
}
Ejemplo n.º 9
0
  /**
   * 描画用マテリアル情報をMQOデータから作成
   *
   * @param mqomat MQOファイルから読み込んだマテリアル情報
   * @param i_mqomat MQOファイルのマテリアル番号
   * @param mqoObjs MQOファイルのオブジェクト情報
   * @param vn 頂点法線配列
   * @return 描画用マテリアル情報
   */
  private GLMaterial makeMats(
      GL10 gl, material mqomat, int i_mqomat, objects mqoObjs, KGLPoint[] vn) {
    GLMaterial ret = new GLMaterial();
    ArrayList<KGLPoint> apv = new ArrayList<KGLPoint>();
    ArrayList<KGLPoint> apn = new ArrayList<KGLPoint>();
    ArrayList<KGLPoint> apuv = new ArrayList<KGLPoint>();
    ArrayList<KGLPoint> apc = new ArrayList<KGLPoint>();
    KGLPoint wpoint = null;
    boolean uvValid = false;
    boolean colValid = false;
    KGLPoint fn;
    float s;
    for (int f = 0; f < mqoObjs.face.length; f++) {
      if (mqoObjs.face[f].M == null) {
        continue;
      }
      if (mqoObjs.face[f].M != i_mqomat) continue;

      fn =
          calcNormal(
              mqoObjs.vertex, mqoObjs.face[f].V[0], mqoObjs.face[f].V[1], mqoObjs.face[f].V[2]);
      for (int v = 0; v < 3; v++) {
        apv.add(mqoObjs.vertex[mqoObjs.face[f].V[v]]);
        // apv.add(new KGLPoint(mqoObjs.vertex[mqoObjs.face[f].V[v]])) ;
        s =
            (float)
                Math.acos(
                    fn.X() * vn[mqoObjs.face[f].V[v]].X()
                        + fn.Y() * vn[mqoObjs.face[f].V[v]].Y()
                        + fn.Z() * vn[mqoObjs.face[f].V[v]].Z());
        if (mqoObjs.data.facet < s) {
          apn.add(fn);
        } else {
          apn.add(vn[mqoObjs.face[f].V[v]]);
        }
        wpoint = new KGLPoint(2);
        if (mqoObjs.face[f].UV == null) {
          wpoint.set_UV(0, 0);
        } else {
          wpoint.set_UV(mqoObjs.face[f].UV[v * 2 + 0], mqoObjs.face[f].UV[v * 2 + 1]);
          uvValid = true;
        }
        apuv.add(wpoint);
        wpoint = new KGLPoint(4);
        if (mqoObjs.face[f].COL == null) {
          if (mqomat.data.col == null) {
            wpoint.set_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
          } else {
            wpoint.set_COLOR(
                mqomat.data.col[0], mqomat.data.col[1], mqomat.data.col[2], mqomat.data.col[3]);
          }
        } else {
          wpoint.set_COLOR(
              mqoObjs.face[f].COL[v * 4 + 0],
              mqoObjs.face[f].COL[v * 4 + 1],
              mqoObjs.face[f].COL[v * 4 + 2],
              mqoObjs.face[f].COL[v * 4 + 3]);
          colValid = true;
        }
        apc.add(wpoint);
      }
    }
    ret.texID = texPool.getGLTexture(gl, mqomat.data.tex, mqomat.data.aplane, false);
    // @@@ reload 用
    if (ret.texID != 0) {
      ret.texName = mqomat.data.tex;
      ret.alphaTexName = mqomat.data.aplane;
    } else {
      ret.texName = null;
      ret.alphaTexName = null;
    }

    if (apv.size() == 0) return null;
    uvValid &= (ret.texID != 0);
    ret.name = mqomat.name;
    // uvValid = false ;
    KGLPoint[] wfv = null;
    KGLPoint[] wfn = null;
    KGLPoint[] wft = null;
    KGLPoint[] wfc = null;
    wfv = apv.toArray(new KGLPoint[0]);
    wfn = apn.toArray(new KGLPoint[0]);
    wft = apuv.toArray(new KGLPoint[0]);
    wfc = apc.toArray(new KGLPoint[0]);
    ret.vertex_num = wfv.length;

    // @@@ interleaveFormat は無いので分ける
    ret.uvValid = uvValid;
    ret.colValid = colValid;

    ret.vertexBuffer = ByteBuffer.allocateDirect(ret.vertex_num * 3 * 4);
    ret.vertexBuffer.order(ByteOrder.nativeOrder());
    ret.vertexBuffer.position(0);

    ret.normalBuffer = ByteBuffer.allocateDirect(ret.vertex_num * 3 * 4);
    ret.normalBuffer.order(ByteOrder.nativeOrder());
    ret.normalBuffer.position(0);

    if (uvValid) {
      ret.uvBuffer = ByteBuffer.allocateDirect(ret.vertex_num * 2 * 4);
      ret.uvBuffer.order(ByteOrder.nativeOrder());
      ret.uvBuffer.position(0);
    }
    if (colValid) {
      ret.colBuffer = ByteBuffer.allocateDirect(ret.vertex_num * 4 * 4);
      ret.colBuffer.order(ByteOrder.nativeOrder());
      ret.colBuffer.position(0);
    }

    // Log.i("KGLMetaseq", "vertex_num: "+ ret.vertex_num);

    for (int v = 0; v < ret.vertex_num; v++) {
      ret.vertexBuffer.putFloat(wfv[v].X());
      ret.vertexBuffer.putFloat(wfv[v].Y());
      ret.vertexBuffer.putFloat(wfv[v].Z());

      ret.normalBuffer.putFloat(wfn[v].X());
      ret.normalBuffer.putFloat(wfn[v].Y());
      ret.normalBuffer.putFloat(wfn[v].Z());

      if (uvValid) {
        ret.uvBuffer.putFloat(wft[v].U());
        ret.uvBuffer.putFloat(wft[v].V());
      }
      if (colValid) {
        ret.colBuffer.putFloat(wfc[v].R());
        ret.colBuffer.putFloat(wfc[v].G());
        ret.colBuffer.putFloat(wfc[v].B());
        ret.colBuffer.putFloat(wfc[v].A());
      }
    }
    if (mqomat.data.col != null) {
      ret.color = new float[mqomat.data.col.length];
      for (int c = 0; c < mqomat.data.col.length; c++) {
        ret.color[c] = mqomat.data.col[c];
      }
      if (mqomat.data.dif != null) {
        ret.dif = new float[mqomat.data.col.length];
        for (int c = 0; c < mqomat.data.col.length; c++) {
          ret.dif[c] = mqomat.data.dif * mqomat.data.col[c];
        }
        // KEICHECK difでアルファ値を1未満にすると透明度が変化する?
        ret.dif[3] = mqomat.data.col[3];
      }
      if (mqomat.data.amb != null) {
        ret.amb = new float[mqomat.data.col.length];
        for (int c = 0; c < mqomat.data.col.length; c++) {
          ret.amb[c] = mqomat.data.amb * mqomat.data.col[c];
        }
      }
      if (mqomat.data.emi != null) {
        ret.emi = new float[mqomat.data.col.length];
        for (int c = 0; c < mqomat.data.col.length; c++) {
          ret.emi[c] = mqomat.data.emi * mqomat.data.col[c];
        }
      }
      if (mqomat.data.spc != null) {
        ret.spc = new float[mqomat.data.col.length];
        for (int c = 0; c < mqomat.data.col.length; c++) {
          ret.spc[c] = mqomat.data.spc * mqomat.data.col[c];
        }
      }
    }
    if (mqomat.data.pow != null) {
      ret.power = new float[1];
      ret.power[0] = mqomat.data.pow;
    }
    ret.shadeMode_IsSmooth = true; // defaultはtrue
    if (mqoObjs.data.shading == 0) ret.shadeMode_IsSmooth = false;

    return ret;
  }
Ejemplo n.º 10
0
 // To add/remove functions change evaluateOperator() and registration
 public double evaluateFunction(String fncnam, ArgParser fncargs) throws ArithmeticException {
   switch (Character.toLowerCase(fncnam.charAt(0))) {
     case 'a':
       {
         if (fncnam.equalsIgnoreCase("abs")) {
           return Math.abs(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("acos")) {
           return Math.acos(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("asin")) {
           return Math.asin(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("atan")) {
           return Math.atan(fncargs.next());
         }
       }
       break;
     case 'c':
       {
         if (fncnam.equalsIgnoreCase("cbrt")) {
           return Math.cbrt(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("ceil")) {
           return Math.ceil(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("cos")) {
           return Math.cos(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("cosh")) {
           return Math.cosh(fncargs.next());
         }
       }
       break;
     case 'e':
       {
         if (fncnam.equalsIgnoreCase("exp")) {
           return Math.exp(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("expm1")) {
           return Math.expm1(fncargs.next());
         }
       }
       break;
     case 'f':
       {
         if (fncnam.equalsIgnoreCase("floor")) {
           return Math.floor(fncargs.next());
         }
       }
       break;
     case 'g':
       {
         //              if(fncnam.equalsIgnoreCase("getExponent"   )) { return
         // Math.getExponent(fncargs.next());                } needs Java 6
       }
       break;
     case 'l':
       {
         if (fncnam.equalsIgnoreCase("log")) {
           return Math.log(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("log10")) {
           return Math.log10(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("log1p")) {
           return Math.log1p(fncargs.next());
         }
       }
       break;
     case 'm':
       {
         if (fncnam.equalsIgnoreCase("max")) {
           return Math.max(fncargs.next(), fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("min")) {
           return Math.min(fncargs.next(), fncargs.next());
         }
       }
       break;
     case 'n':
       {
         //              if(fncnam.equalsIgnoreCase("nextUp"        )) { return Math.nextUp
         // (fncargs.next());                } needs Java 6
       }
       break;
     case 'r':
       {
         if (fncnam.equalsIgnoreCase("random")) {
           return Math.random();
         } // impure
         if (fncnam.equalsIgnoreCase("round")) {
           return Math.round(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("roundHE")) {
           return Math.rint(fncargs.next());
         } // round half-even
       }
       break;
     case 's':
       {
         if (fncnam.equalsIgnoreCase("signum")) {
           return Math.signum(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sin")) {
           return Math.sin(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sinh")) {
           return Math.sinh(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sqrt")) {
           return Math.sqrt(fncargs.next());
         }
       }
       break;
     case 't':
       {
         if (fncnam.equalsIgnoreCase("tan")) {
           return Math.tan(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("tanh")) {
           return Math.tanh(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("toDegrees")) {
           return Math.toDegrees(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("toRadians")) {
           return Math.toRadians(fncargs.next());
         }
       }
       break;
     case 'u':
       {
         if (fncnam.equalsIgnoreCase("ulp")) {
           return Math.ulp(fncargs.next());
         }
       }
       break;
       // no default
   }
   throw new UnsupportedOperationException(
       "MathEval internal function setup is incorrect - internal function \""
           + fncnam
           + "\" not handled");
 }
Ejemplo n.º 11
0
 /**
  * Angle (in radians) between two Pnts (treated as vectors).
  *
  * @param p the other Pnt
  * @return the angle (in radians) between the two Pnts
  */
 public float angle(Pnt p) {
   return (float) Math.acos(this.dot(p) / (this.magnitude() * p.magnitude()));
 }