Exemple #1
0
 public void calc() {
   try {
     // 取得輸入區的字串, 轉成浮點數後除以角度換算單位
     double theta = Double.parseDouble(degree.getText()) / convert;
     // 計算三角函數值, 並將結果寫到各文字欄位中
     sintxt.setText(String.format("%.3f", Math.sin(theta)));
     costxt.setText(String.format("%.3f", Math.cos(theta)));
     tantxt.setText(String.format("%.3f", Math.tan(theta)));
   } catch (NumberFormatException e) {
     degree.setText(""); // 發生例外時清除輸入區內容
   }
 }
Exemple #2
0
  protected void recalcWarpAmount() {
    if (inRate == 0f) return;

    double omegaIn, omegaOut, warp, d1;
    ParamField ggWarp;

    omegaIn = pr.para[PR_INFREQ].val / inRate * Constants.PI2;
    omegaOut = pr.para[PR_OUTFREQ].val / inRate * Constants.PI2;
    d1 = Math.tan((omegaOut - omegaIn) / 2);
    warp =
        Math.max(
            -0.98,
            Math.min(0.98, d1 / (Math.sin(omegaIn) + Math.cos(omegaIn) * d1))); // DAFx2000 'b'

    ggWarp = (ParamField) gui.getItemObj(GG_WARP);
    if (ggWarp != null) {
      ggWarp.setParam(new Param(warp * 100, Param.FACTOR));
    }
  }
 public void skewY(float angle) {
   g2.shear(0, Math.tan(angle));
 }
 /**
  * Gets a list of Point2D objects that lie within pixels in a rectangle and along a line.
  *
  * @param searchRect the rectangle
  * @param x0 the x-component of a point on the line
  * @param y0 the y-component of a point on the line
  * @param slope the slope of the line
  * @return a list of Point2D
  */
 public ArrayList<Point2D> getSearchPoints(
     Rectangle searchRect, double x0, double y0, double theta) {
   double slope = -Math.tan(theta);
   // create line to search along
   Line2D line = new Line2D.Double();
   if (slope > LARGE_NUMBER) {
     line.setLine(x0, y0, x0, y0 + 1);
   } else if (slope < 1 / LARGE_NUMBER) {
     line.setLine(x0, y0, x0 + 1, y0);
   } else {
     line.setLine(x0, y0, x0 + 1, y0 + slope);
   }
   // create intersection points (to set line ends)
   Point2D p1 = new Point2D.Double();
   Point2D p2 = new Point2D.Double(Double.NaN, Double.NaN);
   Point2D p = p1;
   boolean foundBoth = false;
   double d = searchRect.x;
   Object[] data = getDistanceAndPointAtX(line, d);
   if (data != null) {
     p.setLocation((Point2D) data[1]);
     if (p.getY() >= searchRect.y && p.getY() <= searchRect.y + searchRect.height) {
       // line end is left edge
       p = p2;
     }
   }
   d += searchRect.width;
   data = getDistanceAndPointAtX(line, d);
   if (data != null) {
     p.setLocation((Point2D) data[1]);
     if (p.getY() >= searchRect.y && p.getY() <= searchRect.y + searchRect.height) {
       // line end is right edge
       if (p == p1) p = p2;
       else foundBoth = true;
     }
   }
   if (!foundBoth) {
     d = searchRect.y;
     data = getDistanceAndPointAtY(line, d);
     if (data != null) {
       p.setLocation((Point2D) data[1]);
       if (p.getX() >= searchRect.x && p.getX() <= searchRect.x + searchRect.width) {
         // line end is top edge
         if (p == p1) p = p2;
         else if (!p1.equals(p2)) foundBoth = true;
       }
     }
   }
   if (!foundBoth) {
     d += searchRect.height;
     data = getDistanceAndPointAtY(line, d);
     if (data != null) {
       p.setLocation((Point2D) data[1]);
       if (p.getX() >= searchRect.x && p.getX() <= searchRect.x + searchRect.width) {
         // line end is bottom edge
         if (p == p2 && !p1.equals(p2)) foundBoth = true;
       }
     }
   }
   // if both line ends have been found, use line to find pixels to search
   if (foundBoth) {
     // set line ends to intersections
     line.setLine(p1, p2);
     if (p1.getX() > p2.getX()) {
       line.setLine(p2, p1);
     }
     // find pixel intersections that fall along the line
     int xMin = (int) Math.ceil(Math.min(p1.getX(), p2.getX()));
     int xMax = (int) Math.floor(Math.max(p1.getX(), p2.getX()));
     int yMin = (int) Math.ceil(Math.min(p1.getY(), p2.getY()));
     int yMax = (int) Math.floor(Math.max(p1.getY(), p2.getY()));
     // collect intersections in TreeMap sorted by position along line
     TreeMap<Double, Point2D> intersections = new TreeMap<Double, Point2D>();
     for (int x = xMin; x <= xMax; x++) {
       Object[] next = getDistanceAndPointAtX(line, x);
       intersections.put((Double) next[0], (Point2D) next[1]);
     }
     for (int y = yMin; y <= yMax; y++) {
       Object[] next = getDistanceAndPointAtY(line, y);
       intersections.put((Double) next[0], (Point2D) next[1]);
     }
     p = null;
     // create array of search points that are midway between intersections
     ArrayList<Point2D> searchPts = new ArrayList<Point2D>();
     for (Double key : intersections.keySet()) {
       Point2D next = intersections.get(key);
       if (p != null) {
         double x = (p.getX() + next.getX()) / 2 - searchRect.x;
         double y = (p.getY() + next.getY()) / 2 - searchRect.y;
         p.setLocation(x, y);
         searchPts.add(p);
       }
       p = next;
     }
     return searchPts;
   }
   return null;
 }
 public void skewX(float angle) {
   g2.shear(Math.tan(angle), 0);
 }