• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MathUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.vividsolutions.jts.math.MathUtil的典型用法代码示例。如果您正苦于以下问题:Java MathUtil类的具体用法?Java MathUtil怎么用?Java MathUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MathUtil类属于com.vividsolutions.jts.math包,在下文中一共展示了MathUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: precisionScaleFactor

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Compute a scale factor to limit the precision of
 * a given combination of Geometry and buffer distance.
 * The scale factor is determined by
 * the number of digits of precision in the (geometry + buffer distance),
 * limited by the supplied <code>maxPrecisionDigits</code> value.
 * <p>
 * The scale factor is based on the absolute magnitude of the (geometry + buffer distance).
 * since this determines the number of digits of precision which must be handled.
 *
 * @param g the Geometry being buffered
 * @param distance the buffer distance
 * @param maxPrecisionDigits the max # of digits that should be allowed by
 * the precision determined by the computed scale factor
 * @return a scale factor for the buffer computation
 */
private static double precisionScaleFactor(Geometry g,
                                           double distance,
                                           int maxPrecisionDigits) {
    Envelope env = g.getEnvelopeInternal();
    double envMax = MathUtil.max(
            Math.abs(env.getMaxX()),
            Math.abs(env.getMaxY()),
            Math.abs(env.getMinX()),
            Math.abs(env.getMinY())
    );

    double expandByDistance = distance > 0.0 ? distance : 0.0;
    double bufEnvMax = envMax + 2 * expandByDistance;

    // the smallest power of 10 greater than the buffer envelope
    int bufEnvPrecisionDigits = (int) (Math.log(bufEnvMax) / Math.log(10) + 1.0);
    int minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;

    double scaleFactor = Math.pow(10.0, minUnitLog10);
    return scaleFactor;
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:38,代码来源:BufferOp.java


示例2: precisionScaleFactor

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Compute a scale factor to limit the precision of
 * a given combination of Geometry and buffer distance.
 * The scale factor is determined by
 * the number of digits of precision in the (geometry + buffer distance),
 * limited by the supplied <code>maxPrecisionDigits</code> value.
 * <p/>
 * The scale factor is based on the absolute magnitude of the (geometry + buffer distance).
 * since this determines the number of digits of precision which must be handled.
 *
 * @param g                  the Geometry being buffered
 * @param distance           the buffer distance
 * @param maxPrecisionDigits the max # of digits that should be allowed by
 *                           the precision determined by the computed scale factor
 * @return a scale factor for the buffer computation
 */
private static double precisionScaleFactor(Geometry g,
                                           double distance,
                                           int maxPrecisionDigits) {
    Envelope env = g.getEnvelopeInternal();
    double envMax = MathUtil.max(
            Math.abs(env.getMaxX()),
            Math.abs(env.getMaxY()),
            Math.abs(env.getMinX()),
            Math.abs(env.getMinY())
    );

    double expandByDistance = distance > 0.0 ? distance : 0.0;
    double bufEnvMax = envMax + 2 * expandByDistance;

    // the smallest power of 10 greater than the buffer envelope
    int bufEnvPrecisionDigits = (int) (Math.log(bufEnvMax) / Math.log(10) + 1.0);
    int minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;

    double scaleFactor = Math.pow(10.0, minUnitLog10);
    return scaleFactor;
}
 
开发者ID:Semantive,项目名称:jts,代码行数:38,代码来源:BufferOp.java


示例3: extract

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Extracts a subsequence of the input {@link Coordinate} array
 * from indices <code>start</code> to
 * <code>end</code> (inclusive).
 * The input indices are clamped to the array size;
 * If the end index is less than the start index,
 * the extracted array will be empty.
 *
 * @param pts   the input array
 * @param start the index of the start of the subsequence to extract
 * @param end   the index of the end of the subsequence to extract
 * @return a subsequence of the input array
 */
public static Coordinate[] extract(Coordinate[] pts, int start, int end) {
    start = MathUtil.clamp(start, 0, pts.length);
    end = MathUtil.clamp(end, -1, pts.length);

    int npts = end - start + 1;
    if (end < 0) npts = 0;
    if (start >= pts.length) npts = 0;
    if (end < start) npts = 0;

    Coordinate[] extractPts = new Coordinate[npts];
    if (npts == 0) return extractPts;

    int iPts = 0;
    for (int i = start; i <= end; i++) {
        extractPts[iPts++] = pts[i];
    }
    return extractPts;
}
 
开发者ID:Semantive,项目名称:jts,代码行数:32,代码来源:CoordinateArrays.java


示例4: precisionScaleFactor

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Compute a scale factor to limit the precision of
 * a given combination of Geometry and buffer distance.
 * The scale factor is determined by
 * the number of digits of precision in the (geometry + buffer distance),
 * limited by the supplied <code>maxPrecisionDigits</code> value.
 * <p>
 * The scale factor is based on the absolute magnitude of the (geometry + buffer distance).
 * since this determines the number of digits of precision which must be handled.
 *
 * @param g the Geometry being buffered
 * @param distance the buffer distance
 * @param maxPrecisionDigits the max # of digits that should be allowed by
 *          the precision determined by the computed scale factor
 *
 * @return a scale factor for the buffer computation
 */
private static double precisionScaleFactor(Geometry g,
    double distance,
  int maxPrecisionDigits)
{
  Envelope env = g.getEnvelopeInternal();
  double envMax = MathUtil.max(
      Math.abs(env.getMaxX()), 
          Math.abs(env.getMaxY()), 
              Math.abs(env.getMinX()), 
                  Math.abs(env.getMinY())
          );
  
  double expandByDistance = distance > 0.0 ? distance : 0.0;
  double bufEnvMax = envMax + 2 * expandByDistance;

  // the smallest power of 10 greater than the buffer envelope
  int bufEnvPrecisionDigits = (int) (Math.log(bufEnvMax) / Math.log(10) + 1.0);
  int minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;
  
  double scaleFactor = Math.pow(10.0, minUnitLog10);
  return scaleFactor;
}
 
开发者ID:GitHubDroid,项目名称:geodroid_master_update,代码行数:40,代码来源:BufferOp.java


示例5: extract

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Extracts a subsequence of the input {@link Coordinate} array
 * from indices <code>start</code> to
 * <code>end</code> (inclusive).
 * The input indices are clamped to the array size;
 * If the end index is less than the start index,
 * the extracted array will be empty.
 *
 * @param pts the input array
 * @param start the index of the start of the subsequence to extract
 * @param end the index of the end of the subsequence to extract
 * @return a subsequence of the input array
 */
public static Coordinate[] extract(Coordinate[] pts, int start, int end)
{
  start = MathUtil.clamp(start, 0, pts.length);
  end = MathUtil.clamp(end, -1, pts.length);
  
  int npts = end - start + 1;
  if (end < 0) npts = 0;
  if (start >= pts.length) npts = 0;
  if (end < start) npts = 0;
  
  Coordinate[] extractPts = new Coordinate[npts];
  if (npts == 0) return extractPts;
  
  int iPts = 0;
  for (int i = start; i <= end; i++) {
    extractPts[iPts++] = pts[i];
  }
  return extractPts;
}
 
开发者ID:GitHubDroid,项目名称:geodroid_master_update,代码行数:33,代码来源:CoordinateArrays.java


示例6: snapScaleTo_10_2_5

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Not used - scaling to multiples of 10,5,2 is too coarse.
 *  
 * 
 * @param scaleRaw
 * @return
 */
private static double snapScaleTo_10_2_5(double scaleRaw)
{
  // if the rounding error is not nudged, snapping can "stick" at some values
  double pow10 = Math.floor(MathUtil.log10(scaleRaw) + ROUND_ERROR_REMOVAL);
  double scaleRoundedToPow10 = Math.pow(10, pow10);
  
  double scale = scaleRoundedToPow10;
  // rounding to a power of 10 is too coarse, so allow some finer gradations
  //*
  if (3.5 * scaleRoundedToPow10 <= scaleRaw)
    scale = 5 * scaleRoundedToPow10;
  else if (2 * scaleRoundedToPow10 <= scaleRaw)
    scale = 2 * scaleRoundedToPow10;
  //*/
  
  //System.out.println("requested scale = " + scaleRaw + " scale = " + scale  + "   Pow10 = " + pow10);
  return scale;
}
 
开发者ID:dr-jts,项目名称:jeql,代码行数:26,代码来源:Viewport.java


示例7: gridMagnitudeModel

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
   * Gets the magnitude (power of 10)
   * for the basic grid size.
   * 
   * @return
   */
  public int gridMagnitudeModel()
  {
  	double pixelSizeModel = toModel(1);
  	double pixelSizeModelLog = MathUtil.log10(pixelSizeModel);
  	int gridMag = (int) Math.ceil(pixelSizeModelLog);
  	
  	/**
  	 * Check if grid size is too small and if so increase it one magnitude
  	 */
  	double gridSizeModel = Math.pow(10, gridMag);
  	double gridSizeView = toView(gridSizeModel);
//  	System.out.println("\ncand gridSizeView= " + gridSizeView);
  	if (gridSizeView <= MIN_GRID_RESOLUTION_PIXELS )
  		gridMag += 1;
  	
//  	System.out.println("pixelSize= " + pixelSize + "  pixelLog10= " + pixelSizeLog);
  	return gridMag;
  }
 
开发者ID:dr-jts,项目名称:jeql,代码行数:25,代码来源:Viewport.java


示例8: extract

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Extracts a subsequence of the input {@link Coordinate} array
 * from indices <code>start</code> to
 * <code>end</code> (inclusive).
 * The input indices are clamped to the array size;
 * If the end index is less than the start index,
 * the extracted array will be empty.
 *
 * @param pts the input array
 * @param start the index of the start of the subsequence to extract
 * @param end the index of the end of the subsequence to extract
 * @return a subsequence of the input array
 */
public static Coordinate[] extract(Coordinate[] pts, int start, int end) {
    start = MathUtil.clamp(start, 0, pts.length);
    end = MathUtil.clamp(end, -1, pts.length);

    int npts = end - start + 1;
    if (end < 0) {
        npts = 0;
    }
    if (start >= pts.length) {
        npts = 0;
    }
    if (end < start) {
        npts = 0;
    }

    Coordinate[] extractPts = new Coordinate[npts];
    if (npts == 0) {
        return extractPts;
    }

    int iPts = 0;
    for (int i = start; i <= end; i++) {
        extractPts[iPts++] = pts[i];
    }
    return extractPts;
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:40,代码来源:CoordinateArrays.java


示例9: getGeometry

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Gets the {@link MultiPoint} containing the generated point
 *
 * @return a MultiPoint
 */
@Override
public Geometry getGeometry() {
    int nCells = (int) Math.sqrt(this.numPts);
    // ensure that at least numPts points are generated
    if (nCells * nCells < this.numPts) {
        nCells += 1;
    }

    double gridDX = this.getExtent().getWidth() / nCells;
    double gridDY = this.getExtent().getHeight() / nCells;

    double gutterFrac = MathUtil.clamp(this.gutterFraction, 0.0, 1.0);
    double gutterOffsetX = gridDX * gutterFrac / 2;
    double gutterOffsetY = gridDY * gutterFrac / 2;
    double cellFrac = 1.0 - gutterFrac;
    double cellDX = cellFrac * gridDX;
    double cellDY = cellFrac * gridDY;

    Coordinate[] pts = new Coordinate[nCells * nCells];
    int index = 0;
    for (int i = 0; i < nCells; i++) {
        for (int j = 0; j < nCells; j++) {
            double orgX = this.getExtent().getMinX() + i * gridDX + gutterOffsetX;
            double orgY = this.getExtent().getMinY() + j * gridDY + gutterOffsetY;
            pts[index++] = this.randomPointInCell(orgX, orgY, cellDX, cellDY);
        }
    }
    return this.geomFactory.createMultiPoint(pts);
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:35,代码来源:RandomPointsInGridBuilder.java


示例10: getGeometry

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Gets the {@link MultiPoint} containing the generated point
 *
 * @return a MultiPoint
 */
public Geometry getGeometry() {
    int nCells = (int) Math.sqrt(numPts);
    // ensure that at least numPts points are generated
    if (nCells * nCells < numPts)
        nCells += 1;

    double gridDX = getExtent().getWidth() / nCells;
    double gridDY = getExtent().getHeight() / nCells;

    double gutterFrac = MathUtil.clamp(gutterFraction, 0.0, 1.0);
    double gutterOffsetX = gridDX * gutterFrac / 2;
    double gutterOffsetY = gridDY * gutterFrac / 2;
    double cellFrac = 1.0 - gutterFrac;
    double cellDX = cellFrac * gridDX;
    double cellDY = cellFrac * gridDY;

    Coordinate[] pts = new Coordinate[nCells * nCells];
    int index = 0;
    for (int i = 0; i < nCells; i++) {
        for (int j = 0; j < nCells; j++) {
            double orgX = getExtent().getMinX() + i * gridDX + gutterOffsetX;
            double orgY = getExtent().getMinY() + j * gridDY + gutterOffsetY;
            pts[index++] = randomPointInCell(orgX, orgY, cellDX, cellDY);
        }
    }
    return geomFactory.createMultiPoint(pts);
}
 
开发者ID:Semantive,项目名称:jts,代码行数:33,代码来源:RandomPointsInGridBuilder.java


示例11: getGeometry

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Gets the {@link MultiPoint} containing the generated point
 * 
 * @return a MultiPoint
 */
public Geometry getGeometry()
{
  int nCells = (int) Math.sqrt(numPts);
  // ensure that at least numPts points are generated
  if (nCells * nCells < numPts)
    nCells += 1;

  double gridDX = getExtent().getWidth() / nCells;
  double gridDY = getExtent().getHeight() / nCells;

  double gutterFrac = MathUtil.clamp(gutterFraction, 0.0, 1.0);
  double gutterOffsetX = gridDX * gutterFrac/2;
  double gutterOffsetY = gridDY * gutterFrac/2;
  double cellFrac = 1.0 - gutterFrac;
  double cellDX = cellFrac * gridDX;
  double cellDY = cellFrac * gridDY;
  	
  Coordinate[] pts = new Coordinate[nCells * nCells];
  int index = 0;
  for (int i = 0; i < nCells; i++) {
    for (int j = 0; j < nCells; j++) {
    	double orgX = getExtent().getMinX() + i * gridDX + gutterOffsetX;
    	double orgY = getExtent().getMinY() + j * gridDY + gutterOffsetY;
      pts[index++] = randomPointInCell(orgX, orgY, cellDX, cellDY);
    }
  }
  return geomFactory.createMultiPoint(pts);
}
 
开发者ID:GitHubDroid,项目名称:geodroid_master_update,代码行数:34,代码来源:RandomPointsInGridBuilder.java


示例12: temperature

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
public static Color temperature(double fraction) {
	fraction = MathUtil.clamp(fraction, 0, 1);
	int n = temperatureCols.length;
	double index = fraction * (n - 1);
	int low = (int) Math.floor(index);
	int high = (int) Math.ceil(index);
	double ifrac = index - low;
	Color l = temperatureCols[low];
	Color h = temperatureCols[high];
	Color ret = new Color(lerp(l.getRed(), h.getRed(), ifrac), lerp(l.getGreen(), h.getGreen(), ifrac), lerp(l.getBlue(), h.getBlue(), ifrac));
	return ret;
}
 
开发者ID:PGWelch,项目名称:com.opendoorlogistics,代码行数:13,代码来源:Colours.java


示例13: getRenderColour

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
public static Color getRenderColour(DrawableObject pnt, boolean isSelected) {
	if(isSelected){
		return SELECTION_COLOUR;
	}
	Color col = getNoAlphaColour(pnt.getColour(),  pnt.getColourKey());

	double opaque = pnt.getOpaque();
	opaque = MathUtil.clamp(opaque, 0, 1);
	col = Colours.setAlpha(col, (int) Math.round((255 * opaque)));
	return col;
}
 
开发者ID:PGWelch,项目名称:com.opendoorlogistics,代码行数:12,代码来源:DatastoreRenderer.java


示例14: saturate

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
public static Color saturate(Color clr, double saturation)
{
  float[] hsb = new float[3];
  Color.RGBtoHSB(clr.getRed(), clr.getGreen(), clr.getBlue(), hsb);
  hsb[1] = (float) MathUtil.clamp(saturation, 0, 1);;
  return Color.getHSBColor(hsb[0], hsb[1], hsb[2]);
}
 
开发者ID:dr-jts,项目名称:jeql,代码行数:8,代码来源:ColorUtil.java


示例15: maxVisibleMagnitude

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
private int maxVisibleMagnitude()
{
	double visibleExtentModel = viewport.getModelEnv().maxExtent();
	// if input is bogus then just return something reasonable
	if (visibleExtentModel <= 0.0)
		return 1;
	double log10 = MathUtil.log10(visibleExtentModel);
	return (int) log10;
}
 
开发者ID:dr-jts,项目名称:jeql,代码行数:10,代码来源:GridRenderer.java


示例16: setScaleNoUpdate

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
public void setScaleNoUpdate(double scale) {
  this.scale = snapScale(scale);
  scalePM = new PrecisionModel(this.scale);   
  
  scaleFormat = NumberFormat.getInstance();
  int fracDigits = (int) (MathUtil.log10(this.scale));
  if (fracDigits < 0) fracDigits = 0;
  //System.out.println("scale = " + this.scale);
  //System.out.println("fracdigits = " + fracDigits);
  scaleFormat.setMaximumFractionDigits(fracDigits);
  // don't show commas
  scaleFormat.setGroupingUsed(false);
}
 
开发者ID:dr-jts,项目名称:jeql,代码行数:14,代码来源:Viewport.java


示例17: snapScaleToSingleDigitPrecision

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
private static double snapScaleToSingleDigitPrecision(double scaleRaw)
{
  // if the rounding error is not nudged, snapping can "stick" at some values
  double pow10 = Math.floor(MathUtil.log10(scaleRaw) + ROUND_ERROR_REMOVAL);
  double nearestLowerPow10 = Math.pow(10, pow10);
  
  int scaleDigit = (int) (scaleRaw / nearestLowerPow10);
  double scale = scaleDigit * nearestLowerPow10;
  
  //System.out.println("requested scale = " + scaleRaw + " scale = " + scale  + "   Pow10 = " + pow10);
  return scale;
}
 
开发者ID:dr-jts,项目名称:jeql,代码行数:13,代码来源:Viewport.java


示例18: distanceLineLine

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Computes the distance from a line segment AB to a line segment CD
 * <p>
 * Note: NON-ROBUST!
 *
 * @param A a point of one line
 * @param B the second point of (must be different to A)
 * @param C one point of the line
 * @param D another point of the line (must be different to A)
 */
public static double distanceLineLine(Coordinate A, Coordinate B,
                                      Coordinate C, Coordinate D) {
    // check for zero-length segments
    if (A.equals(B)) {
        return distancePointLine(A, C, D);
    }
    if (C.equals(D)) {
        return distancePointLine(D, A, B);
    }

    // AB and CD are line segments
/*
 * from comp.graphics.algo
 * 
 * Solving the above for r and s yields 
 * 
 *     (Ay-Cy)(Dx-Cx)-(Ax-Cx)(Dy-Cy) 
 * r = ----------------------------- (eqn 1) 
 *     (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)
 * 
 *     (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)  
 * s = ----------------------------- (eqn 2)
 *     (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx) 
 *     
 * Let P be the position vector of the
 * intersection point, then 
 *   P=A+r(B-A) or 
 *   Px=Ax+r(Bx-Ax) 
 *   Py=Ay+r(By-Ay) 
 * By examining the values of r & s, you can also determine some other limiting
 * conditions: 
 *   If 0<=r<=1 & 0<=s<=1, intersection exists 
 *      r<0 or r>1 or s<0 or s>1 line segments do not intersect 
 *   If the denominator in eqn 1 is zero, AB & CD are parallel 
 *   If the numerator in eqn 1 is also zero, AB & CD are collinear.
 */

    boolean noIntersection = false;
    if (!Envelope.intersects(A, B, C, D)) {
        noIntersection = true;
    } else {
        double denom = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);

        if (denom == 0) {
            noIntersection = true;
        } else {
            double r_num = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);
            double s_num = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);

            double s = s_num / denom;
            double r = r_num / denom;

            if ((r < 0) || (r > 1) || (s < 0) || (s > 1)) {
                noIntersection = true;
            }
        }
    }
    if (noIntersection) {
        return MathUtil.min(
                distancePointLine(A, C, D),
                distancePointLine(B, C, D),
                distancePointLine(C, A, B),
                distancePointLine(D, A, B));
    }
    // segments intersect
    return 0.0;
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:78,代码来源:CGAlgorithms.java


示例19: distanceLineLine

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
 * Computes the distance from a line segment AB to a line segment CD
 * <p/>
 * Note: NON-ROBUST!
 *
 * @param A a point of one line
 * @param B the second point of (must be different to A)
 * @param C one point of the line
 * @param D another point of the line (must be different to A)
 */
public static double distanceLineLine(Coordinate A, Coordinate B,
                                      Coordinate C, Coordinate D) {
    // check for zero-length segments
    if (A.equals(B))
        return distancePointLine(A, C, D);
    if (C.equals(D))
        return distancePointLine(D, A, B);

    // AB and CD are line segments
/*
 * from comp.graphics.algo
 * 
 * Solving the above for r and s yields 
 * 
 *     (Ay-Cy)(Dx-Cx)-(Ax-Cx)(Dy-Cy) 
 * r = ----------------------------- (eqn 1) 
 *     (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)
 * 
 *     (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)  
 * s = ----------------------------- (eqn 2)
 *     (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx) 
 *     
 * Let P be the position vector of the
 * intersection point, then 
 *   P=A+r(B-A) or 
 *   Px=Ax+r(Bx-Ax) 
 *   Py=Ay+r(By-Ay) 
 * By examining the values of r & s, you can also determine some other limiting
 * conditions: 
 *   If 0<=r<=1 & 0<=s<=1, intersection exists 
 *      r<0 or r>1 or s<0 or s>1 line segments do not intersect 
 *   If the denominator in eqn 1 is zero, AB & CD are parallel 
 *   If the numerator in eqn 1 is also zero, AB & CD are collinear.
 */

    boolean noIntersection = false;
    if (!Envelope.intersects(A, B, C, D)) {
        noIntersection = true;
    } else {
        double denom = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);

        if (denom == 0) {
            noIntersection = true;
        } else {
            double r_num = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);
            double s_num = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);

            double s = s_num / denom;
            double r = r_num / denom;

            if ((r < 0) || (r > 1) || (s < 0) || (s > 1)) {
                noIntersection = true;
            }
        }
    }
    if (noIntersection) {
        return MathUtil.min(
                distancePointLine(A, C, D),
                distancePointLine(B, C, D),
                distancePointLine(C, A, B),
                distancePointLine(D, A, B));
    }
    // segments intersect
    return 0.0;
}
 
开发者ID:Semantive,项目名称:jts,代码行数:76,代码来源:CGAlgorithms.java


示例20: lerp

import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
private static int lerp(int low, int high, double fraction) {
	fraction = MathUtil.clamp(fraction, 0, 1);
	double val = low * (1.0 - fraction) + high * fraction;
	return ensureRange((int) Math.round(val));
}
 
开发者ID:PGWelch,项目名称:com.opendoorlogistics,代码行数:6,代码来源:Colours.java



注:本文中的com.vividsolutions.jts.math.MathUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PeekableIterator类代码示例发布时间:2022-05-23
下一篇:
Java LevelFilterFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap