示例#1
0
 public void setLaunchRodAngle(double launchRodAngle) {
   launchRodAngle = MathUtil.clamp(launchRodAngle, -Math.PI / 6.0, Math.PI / 6.0);
   if (MathUtil.equals(this.getDouble(LAUNCH_ROD_ANGLE, 0), launchRodAngle)) return;
   this.putDouble(LAUNCH_ROD_ANGLE, launchRodAngle);
   ;
   fireChangeEvent();
 }
示例#2
0
  /**
   * Helper function to convert a string representation into a net.sf.openrocket.util.Color object.
   *
   * @param color
   * @return
   */
  protected static Color parseColor(String color) {
    if (color == null) {
      return null;
    }

    String[] rgb = color.split(",");
    if (rgb.length == 3) {
      try {
        int red = MathUtil.clamp(Integer.parseInt(rgb[0]), 0, 255);
        int green = MathUtil.clamp(Integer.parseInt(rgb[1]), 0, 255);
        int blue = MathUtil.clamp(Integer.parseInt(rgb[2]), 0, 255);
        return new Color(red, green, blue);
      } catch (NumberFormatException ignore) {
      }
    }
    return null;
  }
示例#3
0
 public void setLaunchLongitude(double launchLongitude) {
   launchLongitude = MathUtil.clamp(launchLongitude, -180, 180);
   if (MathUtil.equals(this.getDouble(LAUNCH_LONGITUDE, -80.60), launchLongitude)) return;
   this.putDouble(LAUNCH_LONGITUDE, launchLongitude);
   fireChangeEvent();
 }
示例#4
0
 public void setLaunchLatitude(double launchLatitude) {
   launchLatitude = MathUtil.clamp(launchLatitude, -90, 90);
   if (MathUtil.equals(this.getDouble(LAUNCH_LATITUDE, 28.61), launchLatitude)) return;
   this.putDouble(LAUNCH_LATITUDE, launchLatitude);
   fireChangeEvent();
 }
  @Override
  public Variable evaluate(SimulationStatus status) {

    Calculable startCalc = buildExpression(startBuilder);
    Calculable endCalc = buildExpression(endBuilder);
    if (startCalc == null || endCalc == null) {
      return new Variable("Unknown");
    }

    // Set the variables in the start and end calculators
    for (FlightDataType type : status.getFlightData().getTypes()) {
      double value = status.getFlightData().getLast(type);
      startCalc.setVariable(new Variable(type.getSymbol(), value));
      endCalc.setVariable(new Variable(type.getSymbol(), value));
    }

    // From the given datatype, get the time and function values and make an interpolator

    // Note: must get in a way that flight data system will figure out units. Otherwise there will
    // be a type conflict when we get the new data.
    FlightDataType type = FlightDataType.getType(null, getSymbol(), null);

    List<Double> data = status.getFlightData().get(type);
    List<Double> time = status.getFlightData().get(FlightDataType.TYPE_TIME);
    LinearInterpolator interp = new LinearInterpolator(time, data);

    // Evaluate the expression to get the start and end of the range
    double startTime, endTime;
    try {
      startTime = startCalc.calculate().getDoubleValue();
      startTime = MathUtil.clamp(startTime, 0, Double.MAX_VALUE);

      endTime = endCalc.calculate().getDoubleValue();
      endTime = MathUtil.clamp(endTime, 0, time.get(time.size() - 1));
    } catch (java.util.EmptyStackException e) {
      log.info(
          Markers.USER_MARKER,
          "Unable to calculate time index for range expression "
              + getSymbol()
              + " due to empty stack exception");
      return new Variable("Unknown");
    }

    // generate an array representing the range
    double step = status.getSimulationConditions().getSimulation().getOptions().getTimeStep();
    double[] t = ArrayUtils.range(startTime, endTime, step);
    double[] y = new double[t.length];
    int i = 0;
    for (double tval : t) {
      y[i] = interp.getValue(tval);
      i++;
    }

    Variable result;
    if (y.length == 0) {
      result = new Variable("Unknown");
    } else {
      result = new Variable(hash(), y, startTime, step);
    }

    return result;
  }
示例#6
0
 public Appearance(final Color paint, final double shine) {
   this.paint = paint;
   this.shine = MathUtil.clamp(shine, 0, 1);
   this.texture = null;
 }