当前位置: 首页>>代码示例>>Java>>正文


Java Path2D.lineTo方法代码示例

本文整理汇总了Java中java.awt.geom.Path2D.lineTo方法的典型用法代码示例。如果您正苦于以下问题:Java Path2D.lineTo方法的具体用法?Java Path2D.lineTo怎么用?Java Path2D.lineTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.geom.Path2D的用法示例。


在下文中一共展示了Path2D.lineTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawPolyline

import java.awt.geom.Path2D; //导入方法依赖的package包/类
/**
 * Draws a sequence of connected lines defined by
 * arrays of <i>x</i> and <i>y</i> coordinates.
 * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
 * The figure is not closed if the first point
 * differs from the last point.
 * @param       xPoints an array of <i>x</i> points
 * @param       yPoints an array of <i>y</i> points
 * @param       nPoints the total number of points
 * @see         java.awt.Graphics#drawPolygon(int[], int[], int)
 * @since       1.1
 */
public void drawPolyline(int xPoints[], int yPoints[],
                         int nPoints) {

    if (nPoints == 2) {
        draw(new Line2D.Float(xPoints[0], yPoints[0],
                              xPoints[1], yPoints[1]));
    } else if (nPoints > 2) {
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD, nPoints);
        path.moveTo(xPoints[0], yPoints[0]);
        for(int i = 1; i < nPoints; i++) {
            path.lineTo(xPoints[i], yPoints[i]);
        }
        draw(path);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:PathGraphics.java

示例2: makeEllipse

import java.awt.geom.Path2D; //导入方法依赖的package包/类
public Path2D makeEllipse(Complex G1, Complex G2, int m, double xOffset, double yOffset) {
	Path2D path = new Path2D.Float();
	int recPoints = Math.max(minReconstructionSamples, G.length * 3);
	for (int i = 0; i < recPoints; i++) {
		double t = (double) i / recPoints;
		Complex p1 = this.getEllipsePoint(G1, G2, m, t);
		double xt = p1.re();
		double yt = p1.im();
		if (i == 0) {
			path.moveTo(xt + xOffset, yt + yOffset);
		}
		else {
			path.lineTo(xt + xOffset, yt + yOffset);
		}
	}
	path.closePath();
	return path;
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:19,代码来源:FourierDescriptor.java

示例3: convertPolylineToPath

import java.awt.geom.Path2D; //导入方法依赖的package包/类
public static Path2D convertPolylineToPath(final IMapObject mapObject) {
  if (mapObject == null || mapObject.getPolyline() == null || mapObject.getPolyline().getPoints().isEmpty()) {
    return null;
  }

  Path2D path = new Path2D.Float();
  path.moveTo(mapObject.getLocation().getX(), mapObject.getLocation().getY());
  for (int i = 1; i < mapObject.getPolyline().getPoints().size(); i++) {
    Point2D point = mapObject.getPolyline().getPoints().get(i);
    path.lineTo(mapObject.getLocation().getX() + point.getX(), mapObject.getLocation().getY() + point.getY());
  }

  return path;
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:15,代码来源:MapUtilities.java

示例4: retracePath

import java.awt.geom.Path2D; //导入方法依赖的package包/类
private Path retracePath(final AStarNode startNode, final AStarNode targetNode) {
  final List<AStarNode> path = new ArrayList<>();
  AStarNode currentNode = targetNode.getPredecessor();

  while (currentNode != startNode) {
    path.add(currentNode);
    currentNode = currentNode.getPredecessor();
  }
  Collections.reverse(path);

  final Path2D path2D = new GeneralPath(Path2D.WIND_NON_ZERO);
  path2D.moveTo(startNode.getLocation().x, startNode.getLocation().y);

  final List<Point2D> pointsOfPath = new ArrayList<>();
  for (int i = 0; i < path.size(); i++) {
    final AStarNode current = path.get(i);
    final Point currentPoint = new Point(current.getLocation().x, current.getLocation().y);
    pointsOfPath.add(currentPoint);
    path2D.lineTo(currentPoint.x, currentPoint.y);
  }

  path2D.lineTo(targetNode.getLocation().x, targetNode.getLocation().y);

  return new Path(startNode.getLocation(), targetNode.getLocation(), path2D, pointsOfPath);
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:26,代码来源:AStarPathFinder.java

示例5: drawArrow

import java.awt.geom.Path2D; //导入方法依赖的package包/类
private Path2D drawArrow(int x1, int y1, int x2, int y2) {
  Path2D context = new Path2D.Float();
  int headlen = 10;   // length of head in pixels
  double angle = Math.atan2(y2 - y1, x2 - x1);
  context.moveTo(x1, y1);
  context.lineTo(x2, y2);
  context.lineTo(x2 - headlen * Math.cos(angle - Math.PI / 6), y2 - headlen * Math.sin(angle - Math.PI / 6));
  context.moveTo(x2, y2);
  context.lineTo(x2 - headlen * Math.cos(angle + Math.PI / 6), y2 - headlen * Math.sin(angle + Math.PI / 6));
  context.closePath();
  return context;
}
 
开发者ID:onprom,项目名称:onprom,代码行数:13,代码来源:ResourceConnection.java

示例6: renderCurvePath

import java.awt.geom.Path2D; //导入方法依赖的package包/类
private Shape renderCurvePath(int[] xPoints, int[] yPoints) {
    Path2D path = new Path2D.Double();
    path.moveTo(xPoints[0], yPoints[0]);

    int curveIndex;
    for (curveIndex = 0; curveIndex <= xPoints.length - 3; curveIndex += 3) {
        path.curveTo(xPoints[curveIndex], yPoints[curveIndex], xPoints[curveIndex + 1], yPoints[curveIndex + 1], xPoints[curveIndex + 2], yPoints[curveIndex + 2]);
    }

    if (xPoints.length >= 3 && xPoints.length - curveIndex == 2) {
        path.curveTo(xPoints[xPoints.length - 3], yPoints[xPoints.length - 3], xPoints[xPoints.length - 2], yPoints[xPoints.length - 2], xPoints[xPoints.length - 1], yPoints[xPoints.length - 1]);
    } else {
        path.lineTo(xPoints[xPoints.length - 1], yPoints[xPoints.length - 1]);
    }

    return path;
}
 
开发者ID:defano,项目名称:jmonet,代码行数:18,代码来源:CurveTool.java

示例7: main

import java.awt.geom.Path2D; //导入方法依赖的package包/类
public static void main(final String[] args) {
    final Path2D path1 = new Path2D.Double(Path2D.WIND_EVEN_ODD, 0);
    path1.moveTo(10, 10);
    path1.lineTo(20, 20);
    final Path2D path2 = new Path2D.Float(Path2D.WIND_EVEN_ODD, 0);
    path2.moveTo(10, 10);
    path2.lineTo(20, 20);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:EmptyCapacity.java

示例8: makePolygon

import java.awt.geom.Path2D; //导入方法依赖的package包/类
@Deprecated
public static Roi makePolygon(Point2D[] points, double strokeWidth, Color color) {
	Path2D poly = new Path2D.Double();
	if (points.length > 0) {
		poly.moveTo(points[0].getX(), points[0].getY());
		for (int i = 1; i < points.length; i++) {
			poly.lineTo(points[i].getX(), points[i].getY());
		}
		poly.closePath();
	}
	Roi shapeRoi = new ShapeRoi(poly);
	shapeRoi.setStrokeWidth(strokeWidth);
	shapeRoi.setStrokeColor(color);
	return shapeRoi;
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:16,代码来源:RoiUtils.java

示例9: makeFourierPairsReconstruction

import java.awt.geom.Path2D; //导入方法依赖的package包/类
/**
 * Reconstructs the shape obtained from FD-pairs 0,...,Mp as a polygon (path).
 * 
 * @param Mp number of Fourier coefficient pairs
 * @return reconstructed shape
 */
public Path2D makeFourierPairsReconstruction(int Mp) {
	int M = G.length;
	Mp = Math.min(Mp, M/2);
	int recPoints = Math.max(minReconstructionSamples, G.length * 3);
	Path2D path = new Path2D.Float();
	for (int i = 0; i < recPoints; i++) {
		double t = (double) i / recPoints;
		Complex pt = new Complex(getCoefficient(0));	// assumes that coefficient 0 is never scaled
		// calculate a particular reconstruction point 
		for (int m = 1; m <= Mp; m++) {
			Complex ep = getEllipsePoint(getCoefficient(-m), getCoefficient(m), m, t);
			pt = pt.add(ep.mult(reconstructionScale));
		}
		double xt = pt.re(); 
		double yt = pt.im(); 
		if (i == 0) {
			path.moveTo(xt, yt);
		}
		else {
			path.lineTo(xt, yt);
		}
	}
	path.closePath();
	return path;
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:32,代码来源:FourierDescriptor.java

示例10: findDirectPath

import java.awt.geom.Path2D; //导入方法依赖的package包/类
public Path findDirectPath(final Point2D start, final Point2D target) {
  final Path2D path2D = new GeneralPath(Path2D.WIND_NON_ZERO);
  path2D.moveTo(start.getX(), start.getY());
  path2D.lineTo(target.getX(), target.getY());

  final List<Point2D> points = new ArrayList<>();
  points.add(start);
  points.add(target);
  return new Path(start, target, path2D, points);
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:11,代码来源:PathFinder.java

示例11: drawPolylineGOOD

import java.awt.geom.Path2D; //导入方法依赖的package包/类
private void drawPolylineGOOD(Graphics2D g2d,
                              int[] x2Points, int[] y2Points) {

    Path2D polyline =
        new Path2D.Float(Path2D.WIND_EVEN_ODD, x2Points.length);

    polyline.moveTo(x2Points[0], y2Points[0]);

    for (int index = 1; index < x2Points.length; index++) {
            polyline.lineTo(x2Points[index], y2Points[index]);
    }
    g2d.draw(polyline);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:PolylinePrintingTest.java

示例12: renderLightSource

import java.awt.geom.Path2D; //导入方法依赖的package包/类
private void renderLightSource(final Graphics2D g, final LightSource light, final double longerDimension) {
  final Point2D lightCenter = light.getDimensionCenter();

  final Area lightArea = new Area(light.getLightShape());
  if (light.getLightShapeType().equals(LightSource.RECTANGLE)) {
    g.setColor(light.getColor());
    g.fill(lightArea);
    return;
  }

  // cut the light area where shadow Boxes are (this simulates light falling
  // into and out of rooms)
  for (final StaticShadow col : this.environment.getStaticShadows()) {
    if (!GeometricUtilities.shapeIntersects(light.getLightShape(), col.getBoundingBox())) {
      continue;
    }
    final Area boxInLight = new Area(col.getBoundingBox());
    boxInLight.intersect(lightArea);

    final Line2D[] bounds = GeometricUtilities.getLines(col.getBoundingBox());
    for (final Line2D line : bounds) {
      final Vector2D lineVector = new Vector2D(line.getP1(), line.getP2());
      final Vector2D lightVector = new Vector2D(lightCenter, line.getP1());

      if (light.getDimensionCenter().getY() < line.getY1() && light.getDimensionCenter().getY() < line.getY2() && col.getBoundingBox().contains(light.getDimensionCenter()) || lineVector.normalVector().dotProduct(lightVector) >= 0) {
        continue;
      }

      final Path2D shadowParallelogram = new Path2D.Double();
      final Point2D shadowPoint1 = GeometricUtilities.project(lightCenter, line.getP1(), longerDimension);
      final Point2D shadowPoint2 = GeometricUtilities.project(lightCenter, line.getP2(), longerDimension);

      // construct a shape from our points
      shadowParallelogram.moveTo(line.getP1().getX(), line.getP1().getY());
      shadowParallelogram.lineTo(shadowPoint1.getX(), shadowPoint1.getY());
      shadowParallelogram.lineTo(shadowPoint2.getX(), shadowPoint2.getY());
      shadowParallelogram.lineTo(line.getP2().getX(), line.getP2().getY());
      shadowParallelogram.closePath();

      final Area shadowArea = new Area(shadowParallelogram);
      if (light.getDimensionCenter().getY() < col.getBoundingBox().getMaxY() && !col.getBoundingBox().contains(light.getDimensionCenter())) {
        shadowArea.add(boxInLight);
      }
      shadowArea.intersect(lightArea);
      lightArea.subtract(shadowArea);
    }
  }

  final Paint oldPaint = g.getPaint();

  // render parts that lie within the shadow with a gradient from the light
  // color to transparent
  final Area lightRadiusArea = new Area(light.getLightShape());
  final Color[] transColors = new Color[] { new Color(light.getColor().getRed(), light.getColor().getGreen(), light.getColor().getBlue(), light.getBrightness()), new Color(light.getColor().getRed(), light.getColor().getGreen(), light.getColor().getBlue(), 0) };
  try {
    g.setPaint(new RadialGradientPaint(new Point2D.Double(lightRadiusArea.getBounds2D().getCenterX(), lightRadiusArea.getBounds2D().getCenterY()), (float) (lightRadiusArea.getBounds2D().getWidth() / 2), new float[] { 0.0f, 1.00f }, transColors));
  } catch (final Exception e) {
    g.setColor(light.getColor());
  }
  g.fill(lightArea);
  g.setPaint(oldPaint);
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:63,代码来源:AmbientLight.java

示例13: getShape

import java.awt.geom.Path2D; //导入方法依赖的package包/类
@Override
public Shape getShape() {
  Path2D shape = new Path2D.Float();
  int xDiff = Math.abs(getSuperclass().getCenterX() - getSubclass().getCenterX());
  int yDiff = Math.abs(getSuperclass().getCenterY() - getSubclass().getCenterY());
  if (xDiff > 2 * yDiff) {
    if (getSuperclass().getStartX() > getSubclass().getEndX()) {
      trianglePosition = Position.LEFT;
      shape.moveTo(getSuperclass().getStartX(), getSuperclass().getCenterY());
      shape.lineTo(getSuperclass().getStartX() - cos30,
        getSuperclass().getCenterY() - sin30);
      shape.lineTo(getSuperclass().getStartX() - cos30,
        getSuperclass().getCenterY() - sinNeg30);
      shape.lineTo(getSuperclass().getStartX(), getSuperclass().getCenterY());
    } else if (getSuperclass().getEndX() < getSubclass().getStartX()) {
      trianglePosition = Position.RIGHT;
      shape.moveTo(getSuperclass().getEndX(), getSuperclass().getCenterY());
      shape.lineTo(getSuperclass().getEndX() + cos30,
        getSuperclass().getCenterY() + sin30);
      shape.lineTo(getSuperclass().getEndX() + cos30,
        getSuperclass().getCenterY() + sinNeg30);
      shape.lineTo(getSuperclass().getEndX(), getSuperclass().getCenterY());
    }
  } else {
    if (getSuperclass().getStartY() > getSubclass().getEndY()) {
      trianglePosition = Position.TOP;
      shape.moveTo(getSuperclass().getCenterX(), getSuperclass().getStartY());
      shape.lineTo(getSuperclass().getCenterX() - sin30,
        getSuperclass().getStartY() - cos30);// 30°
      shape.lineTo(getSuperclass().getCenterX() - sinNeg30,
        getSuperclass().getStartY() - cosNeg30);// 30°
      shape.lineTo(getSuperclass().getCenterX(), getSuperclass().getStartY());
    } else {
      trianglePosition = Position.BOTTOM;
      shape.moveTo(getSuperclass().getCenterX(), getSuperclass().getEndY());
      shape.lineTo(getSuperclass().getCenterX() + sin30,
        getSuperclass().getEndY() + cos30);// 30°
      shape.lineTo(getSuperclass().getCenterX() + sinNeg30,
        getSuperclass().getEndY() + cosNeg30);// 30°
      shape.lineTo(getSuperclass().getCenterX(), getSuperclass().getEndY());
    }
  }
  try {
    shape.closePath();
  } catch (IllegalPathStateException e) {
    return super.getShape();
  }
  shape.append(super.getShape(), false);
  return shape;
}
 
开发者ID:onprom,项目名称:onprom,代码行数:51,代码来源:Inheritance.java

示例14: addLines

import java.awt.geom.Path2D; //导入方法依赖的package包/类
static Path2D addLines(Path2D p2d) {
    for (int i = 0; i < 10; i++) {
        p2d.lineTo(1.1 * i, 2.3 * i);
    }
    return p2d;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:Path2DCopyConstructor.java

示例15: addLine

import java.awt.geom.Path2D; //导入方法依赖的package包/类
static void addLine(Path2D p2d, int i) {
    p2d.lineTo(1.1 * i, 2.3 * i);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:4,代码来源:Path2DGrow.java


注:本文中的java.awt.geom.Path2D.lineTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。