gpt4 book ai didi

gov.nasa.worldwind.util.WWMath类的使用及代码示例

转载 作者:知者 更新时间:2024-03-23 01:35:05 27 4
gpt4 key购买 nike

本文整理了Java中gov.nasa.worldwind.util.WWMath类的一些代码示例,展示了WWMath类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WWMath类的具体详情如下:
包路径:gov.nasa.worldwind.util.WWMath
类名称:WWMath

WWMath介绍

[英]Collection of static methods for performing common WorldWind computations.
[中]用于执行常见WorldWind计算的静态方法集合。

代码示例

代码示例来源:origin: Berico-Technologies/Geo-Coordinate-Conversion-Java

/**
 * Returns the interpolation factor for <code>v</code> given the specified range <code>[x, y]</code>. The
 * interpolation factor is a number between 0 and 1 (inclusive), representing the value's relative position between
 * <code>x</code> and <code>y</code>. For example, 0 corresponds to <code>x</code>, 1 corresponds to <code>y</code>,
 * and anything in between corresponds to a linear combination of <code>x</code> and <code>y</code>.
 *
 * @param v the value to compute the interpolation factor for.
 * @param x the first value.
 * @param y the second value.
 *
 * @return the interpolation factor for <code>v</code> given the specified range <code>[x, y]</code>
 */
public static double computeInterpolationFactor(double v, double x, double y)
{
  return clamp((v - x) / (y - x), 0d, 1d);
}

代码示例来源:origin: senbox-org/s1tbx

private static AnalyticSurface.GridPointAttributes createColorGradientAttributes(final double value,
                                         double minValue, double maxValue,
                                         double minHue, double maxHue,
                                         boolean whiteZero) {
  final double hueFactor = WWMath.computeInterpolationFactor(value, minValue, maxValue);
  //double hue = WWMath.mixSmooth(hueFactor, minHue, maxHue);
  final double hue = WWMath.mix(hueFactor, minHue, maxHue);
  double sat = 1.0;
  if (whiteZero) {
    sat = Math.abs(WWMath.mixSmooth(hueFactor, -1, 1));
  }
  final Color color = Color.getHSBColor((float) hue, (float) sat, 1f);
  final double opacity = WWMath.computeInterpolationFactor(value, minValue, minValue + (maxValue - minValue) * 0.1);
  final Color rgbaColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) (255 * opacity));
  return AnalyticSurface.createGridPointAttributes(value, rgbaColor);
}

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

/**
 * Computes the linear interpolation of two angles in the range [0, 360] degrees according to a specified fractional
 * amount. The fractional amount is interpreted as a relative proportion of the two angles, where 0.0 indicates the
 * first angle, 0.5 indicates an angle half way between the two angles, and 1.0 indicates the second angle.
 * <p/>
 * The result of this method is undefined if the amount is outside the range [0, 1].
 *
 * @param amount   the fractional proportion of the two angles in the range [0, 1]
 * @param degrees1 the first angle in degrees
 * @param degrees2 the second angle in degrees
 *
 * @return the interpolated angle in the range [0, 360] degrees
 */
public static double interpolateAngle360(double amount, double degrees1, double degrees2) {
  // Normalize the two angles to the range [-180, +180].
  double angle1 = normalizeAngle180(degrees1);
  double angle2 = normalizeAngle180(degrees2);
  // If the shortest arc between the two angles crosses the -180/+180 degree boundary, add 360 degrees to the
  // smaller of the two angles then interpolate.
  if (angle1 - angle2 > 180) {
    angle2 += 360;
  } else if (angle1 - angle2 < -180) {
    angle1 += 360;
  }
  // Linearly interpolate between the two angles then normalize the interpolated result. Normalizing the result is
  // necessary when we have added 360 degrees to either angle in order to interpolate along the shortest arc.
  double angle = (1 - amount) * angle1 + amount * angle2;
  return normalizeAngle360(angle);
}

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

int widthPow2 = WWMath.powerOfTwoCeiling(width);
int bytesPerRow = widthPow2 * 4;
switch (type) {
int heightPow2 = WWMath.powerOfTwoCeiling(height);
int byteCount = bytesPerRow * heightPow2;
boolean isPowerOfTwo = WWMath.isPowerOfTwo(width) && WWMath.isPowerOfTwo(height);
if (isPowerOfTwo) {
  byteCount += byteCount / 3;

代码示例来源:origin: senbox-org/snap-desktop

protected BufferedImage createColorGradientLegendImage(final int width, final int height,
                            final double minHue, final double maxHue,
                            final Color borderColor, final boolean whiteZero) {
  //System.out.println("createColorGradientLegendImage " + minHue + " " + maxHue);
  final BufferedImage image = new BufferedImage(width, height,
                         BufferedImage.TYPE_4BYTE_ABGR);
  final Graphics2D g2d = image.createGraphics();
  try {
    for (int y = 0; y < height; y++) {
      double a = 1d - y / (double) (height - 1);
      double hue = WWMath.mix(a, minHue, maxHue);
      double sat = 1.0;
      if (whiteZero) {
        sat = Math.abs(WWMath.mix(a, -1, 1));
      }
      g2d.setColor(Color.getHSBColor((float) hue, (float) sat, 1f));
      g2d.drawLine(0, y, width - 1, y);
    }
    if (borderColor != null) {
      g2d.setColor(borderColor);
      g2d.drawRect(0, 0, width - 1, height - 1);
    }
  } finally {
    g2d.dispose();
  }
  return image;
}

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

double v = rasterHeight * WWMath.clamp(t, tMin, tMax); // clamp the vertical coordinate to the raster edge
float b = (float) WWMath.fract(v - 0.5);
int j0 = (int) WWMath.clamp(Math.floor(v - 0.5), 0, rasterHeight - 1);
int j1 = (int) WWMath.clamp(j0 + 1, 0, rasterHeight - 1);
int row0 = j0 / tileHeight;
int row1 = j1 / tileHeight;
  int i0, i1;
  if (tileBlock.tileMatrix.sector.isFullSphere()) {
    u = rasterWidth * WWMath.fract(s); // wrap the horizontal coordinate
    i0 = WWMath.mod((int) Math.floor(u - 0.5), rasterWidth);
    i1 = WWMath.mod((i0 + 1), rasterWidth);
  } else {
    u = rasterWidth * WWMath.clamp(s, sMin, sMax); // clamp the horizontal coordinate
    i0 = (int) WWMath.clamp((int) Math.floor(u - 0.5), 0, rasterWidth - 1);
    i1 = (int) WWMath.clamp((i0 + 1), 0, rasterWidth - 1);
  float a = (float) WWMath.fract(u - 0.5);
  int col0 = i0 / tileWidth;
  int col1 = i1 / tileWidth;

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

@Test
public void testNormalizeDegrees() throws Exception {
  // Starting at the prime meridian, travel eastward around the globe
  assertEquals("zero", 0.0, WWMath.normalizeAngle360(0.0), 0);
  assertEquals("180", 180.0, WWMath.normalizeAngle360(180.0), 0);
  assertEquals("181", 181.0, WWMath.normalizeAngle360(181.0), 0);
  assertEquals("359", 359.0, WWMath.normalizeAngle360(359.0), 0);
  assertEquals("360", 0.0, WWMath.normalizeAngle360(360.0), 0);
  assertEquals("361", 1.0, WWMath.normalizeAngle360(361.0), 0);
  assertEquals("720", 0.0, WWMath.normalizeAngle360(720.0), 0);
  assertEquals("721", 1.0, WWMath.normalizeAngle360(721.0), 0);
  // Starting at the prime meridian, travel westward around the globe
  assertEquals("-1", 359.0, WWMath.normalizeAngle360(-1.0), 0);
  assertEquals("-359", 1.0, WWMath.normalizeAngle360(-359.0), 0);
  assertEquals("-360", 0.0, WWMath.normalizeAngle360(-360.0), 0);
  assertEquals("-361", 359.0, WWMath.normalizeAngle360(-361.0), 0);
  assertEquals("-719", 1.0, WWMath.normalizeAngle360(-719.0), 0);
  assertEquals("-720", 0.0, WWMath.normalizeAngle360(-720.0), 0);
  assertEquals("-721", 359.0, WWMath.normalizeAngle360(-721.0), 0);
  // NaN should be propagated
  assertTrue("NaN", Double.isNaN(WWMath.normalizeAngle360(Double.NaN)));
}

代码示例来源:origin: Berico-Technologies/Geo-Coordinate-Conversion-Java

/**
 * Convenience method for testing whether a value is a power of two.
 *
 * @param value the value to test for power of 2
 *
 * @return true if power of 2, else false
 */
public static boolean isPowerOfTwo(int value)
{
  return (value == powerOfTwoCeiling(value));
}

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

@Override
  public void run() {
    this.wwd.getNavigator().getAsCamera(this.wwd.getGlobe(), this.beginCamera);
    this.beginPos.set(this.beginCamera.latitude, this.beginCamera.longitude, this.beginCamera.altitude);
    for (int i = 0; i < this.steps; i++) {
      double amount = (double) i / (double) (this.steps - 1);
      this.beginPos.interpolateAlongPath(this.endPos, WorldWind.GREAT_CIRCLE, amount, this.curPos);
      this.curCamera.latitude = this.curPos.latitude;
      this.curCamera.longitude = this.curPos.longitude;
      this.curCamera.altitude = this.curPos.altitude;
      this.curCamera.heading = WWMath.interpolateAngle360(amount, this.beginCamera.heading, this.endCamera.heading);
      this.curCamera.tilt = WWMath.interpolateAngle180(amount, this.beginCamera.tilt, this.endCamera.tilt);
      this.curCamera.roll = WWMath.interpolateAngle180(amount, this.beginCamera.roll, this.endCamera.roll);
      Runnable setCommand = SetCameraCommand.obtain(this.wwd, this.curCamera);
      runOnActivityThread(setCommand);
      sleepQuietly(FRAME_INTERVAL);
    }
  }
}

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

WWMath.boundingRectForUnitSquare(renderData.unitSquareTransform, renderData.screenBounds);
if (!rc.frustum.intersectsViewport(renderData.screenBounds)) {
  return; // the text is outside the viewport

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

double s = (longitude - sector.minLongitude()) / sector.deltaLongitude() * (tileWidth - 1);
double t = (latitude - sector.minLatitude()) / sector.deltaLatitude() * (tileHeight - 1);
double sf = (s < tileWidth - 1) ? WWMath.fract(s) : 1;
double tf = (t < tileHeight - 1) ? WWMath.fract(t) : 1;
int si = (s < tileWidth - 1) ? (int) (s + 1) : (tileWidth - 1);
int ti = (t < tileHeight - 1) ? (int) (t + 1) : (tileHeight - 1);

代码示例来源:origin: Berico-Technologies/Geo-Coordinate-Conversion-Java

/**
 * Returns the an interpolated location along the great-arc between <code>value1</code> and <code>value2</code>. The
 * position's elevation components are linearly interpolated as a simple 1D scalar value. The interpolation factor
 * <code>amount</code> defines the weight given to each value, and is clamped to the range [0, 1]. If <code>a</code>
 * is 0 or less, this returns <code>value1</code>. If <code>amount</code> is 1 or more, this returns
 * <code>value2</code>. Otherwise, this returns the position on the great-arc between <code>value1</code> and
 * <code>value2</code> with a linearly interpolated elevation component, and corresponding to the specified
 * interpolation factor.
 *
 * @param amount the interpolation factor
 * @param value1 the first position.
 * @param value2 the second position.
 *
 * @return an interpolated position along the great-arc between <code>value1</code> and <code>value2</code>, with a
 *         linearly interpolated elevation component.
 *
 * @throws IllegalArgumentException if either location is null.
 */
public static Position interpolateGreatCircle(double amount, Position value1, Position value2)
{
  if (value1 == null || value2 == null)
  {
    throw new IllegalArgumentException("Position Is Null");
  }
  LatLon latLon = LatLon.interpolateGreatCircle(amount, value1, value2);
  // Elevation is independent of geographic interpolation method (i.e. rhumb, great-circle, linear), so we
  // interpolate elevation linearly.
  double elevation = WWMath.mix(amount, value1.getElevation(), value2.getElevation());
  return new Position(latLon, elevation);
}

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

int i0, i1;
if (tileMatrix.sector.isFullSphere()) {
  u = rasterWidth * WWMath.fract(s); // wrap the horizontal coordinate
  i0 = WWMath.mod((int) Math.floor(u - 0.5), rasterWidth);
  i1 = WWMath.mod((i0 + 1), rasterWidth);
} else {
  u = rasterWidth * WWMath.clamp(s, sMin, sMax); // clamp the horizontal coordinate
  i0 = (int) WWMath.clamp((int) Math.floor(u - 0.5), 0, rasterWidth - 1);
  i1 = (int) WWMath.clamp((i0 + 1), 0, rasterWidth - 1);
double v = rasterHeight * WWMath.clamp(t, tMin, tMax); // clamp the vertical coordinate to the raster edge
int j0 = (int) WWMath.clamp(Math.floor(v - 0.5), 0, rasterHeight - 1);
int j1 = (int) WWMath.clamp(j0 + 1, 0, rasterHeight - 1);
int row0 = j0 / tileHeight;
int row1 = j1 / tileHeight;

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

this.lookAt.latitude = Location.normalizeLatitude(lat);
  this.lookAt.longitude = Location.normalizeLongitude(lon + 180);
  this.lookAt.heading = WWMath.normalizeAngle360(heading + 180);
} else if (lon < -180 || lon > 180) {
  this.lookAt.latitude = lat;

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

WWMath.boundingRectForUnitSquare(unitSquareTransform, screenBounds);
if (rc.frustum.intersectsViewport(screenBounds)) {
  Pool<DrawableScreenTexture> pool = rc.getDrawablePool(DrawableScreenTexture.class);

代码示例来源:origin: Berico-Technologies/Geo-Coordinate-Conversion-Java

/**
 * Returns the linear interpolation of <code>x</code> and <code>y</code> according to the function: <code>(1 - a) *
 * x + a * y</code>. The interpolation factor <code>a</code> defines the weight given to each value, and is clamped
 * to the range [0, 1]. If <code>a</code> is 0 or less, this returns x. If <code>a</code> is 1 or more, this returns
 * <code>y</code>. Otherwise, this returns the linear interpolation of <code>x</code> and <code>y</code>. For
 * example, when <code>a</code> is <code>0.5</code> this returns <code>(x + y)/2</code>.
 *
 * @param a the interpolation factor.
 * @param x the first value.
 * @param y the second value.
 *
 * @return the linear interpolation of <code>x</code> and <code>y</code>.
 */
public static double mix(double a, double x, double y)
{
  double t = clamp(a, 0d, 1d);
  return x + t * (y - x);
}

代码示例来源:origin: Berico-Technologies/Geo-Coordinate-Conversion-Java

/**
 * Returns the linear interpolation of <code>value1</code> and <code>value2</code>, treating the geographic
 * locations as simple 2D coordinate pairs, and treating the elevation values as 1D scalars.
 *
 * @param amount the interpolation factor
 * @param value1 the first position.
 * @param value2 the second position.
 *
 * @return the linear interpolation of <code>value1</code> and <code>value2</code>.
 *
 * @throws IllegalArgumentException if either position is null.
 */
public static Position interpolate(double amount, Position value1, Position value2)
{
  if (value1 == null || value2 == null)
  {
    throw new IllegalArgumentException("Position Is Null");
  }
  if (amount < 0)
    return value1;
  else if (amount > 1)
    return value2;
  LatLon latLon = LatLon.interpolate(amount, value1, value2);
  // Elevation is independent of geographic interpolation method (i.e. rhumb, great-circle, linear), so we
  // interpolate elevation linearly.
  double elevation = WWMath.mix(amount, value1.getElevation(), value2.getElevation());
  return new Position(latLon, elevation);
}

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

@Override
protected void handleRotate(GestureRecognizer recognizer) {
  int state = recognizer.getState();
  float rotation = ((RotationRecognizer) recognizer).getRotation();
  if (state == WorldWind.BEGAN) {
    this.gestureDidBegin();
    this.lastRotation = 0;
  } else if (state == WorldWind.CHANGED) {
    // Apply the change in rotation to the navigator, relative to the navigator's current values.
    double headingDegrees = this.lastRotation - rotation;
    this.camera.heading = WWMath.normalizeAngle360(this.camera.heading + headingDegrees);
    this.lastRotation = rotation;
    this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera);
    this.wwd.requestRedraw();
  } else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) {
    this.gestureDidEnd();
  }
}

代码示例来源:origin: Berico-Technologies/Geo-Coordinate-Conversion-Java

/**
 * Returns the smooth hermite interpolation of <code>x</code> and <code>y</code> according to the function: <code>(1
 * - t) * x + t * y</code>, where <code>t = a * a * (3 - 2 * a)</code>. The interpolation factor <code>a</code>
 * defines the weight given to each value, and is clamped to the range [0, 1]. If <code>a</code> is 0 or less, this
 * returns <code>x</code>. If <code>a</code> is 1 or more, this returns <code>y</code>. Otherwise, this returns the
 * smooth hermite interpolation of <code>x</code> and <code>y</code>. Like the linear function {@link #mix(double,
 * double, double)}, when <code>a</code> is <code>0.5</code> this returns <code>(x + y)/2</code>. But unlike the
 * linear function, the hermite function's slope gradually increases when <code>a</code> is near 0, then gradually
 * decreases when <code>a</code> is near 1. This is a useful property where a more gradual transition from
 * <code>x</code> to <code>y</code> is desired.
 *
 * @param a the interpolation factor.
 * @param x the first value.
 * @param y the second value.
 *
 * @return the smooth hermite interpolation of <code>x</code> and <code>y</code>.
 */
public static double mixSmooth(double a, double x, double y)
{
  double t = clamp(a, 0d, 1d);
  t = t * t * (3d - 2d * t);
  return x + t * (y - x);
}

代码示例来源:origin: Berico-Technologies/Geo-Coordinate-Conversion-Java

/**
 * Returns the an interpolated location along the rhumb line between <code>value1</code> and <code>value2</code>.
 * The position's elevation components are linearly interpolated as a simple 1D scalar value. The interpolation
 * factor <code>amount</code> defines the weight given to each value, and is clamped to the range [0, 1]. If
 * <code>a</code> is 0 or less, this returns <code>value1</code>. If <code>amount</code> is 1 or more, this returns
 * <code>value2</code>. Otherwise, this returns the position on the rhumb line between <code>value1</code> and
 * <code>value2</code> with a linearly interpolated elevation component, and corresponding to the specified
 * interpolation factor.
 *
 * @param amount the interpolation factor
 * @param value1 the first position.
 * @param value2 the second position.
 *
 * @return an interpolated position along the great-arc between <code>value1</code> and <code>value2</code>, with a
 *         linearly interpolated elevation component.
 *
 * @throws IllegalArgumentException if either location is null.
 */
public static Position interpolateRhumb(double amount, Position value1, Position value2)
{
  if (value1 == null || value2 == null)
  {
    throw new IllegalArgumentException("Position Is Null");
  }
  LatLon latLon = LatLon.interpolateRhumb(amount, value1, value2);
  // Elevation is independent of geographic interpolation method (i.e. rhumb, great-circle, linear), so we
  // interpolate elevation linearly.
  double elevation = WWMath.mix(amount, value1.getElevation(), value2.getElevation());
  return new Position(latLon, elevation);
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com