本文整理汇总了Java中java.awt.geom.Line2D.getY2方法的典型用法代码示例。如果您正苦于以下问题:Java Line2D.getY2方法的具体用法?Java Line2D.getY2怎么用?Java Line2D.getY2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.Line2D
的用法示例。
在下文中一共展示了Line2D.getY2方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPerpendicularIntersection
import java.awt.geom.Line2D; //导入方法依赖的package包/类
/**
* Gets the perpendicular intersection.
*
* @param point
* the point
* @param line
* the line
* @return the perpendicular intersection
*/
public static Point2D getPerpendicularIntersection(final Point2D point, final Line2D line) {
final double x1 = line.getX1();
final double y1 = line.getY1();
final double x2 = line.getX2();
final double y2 = line.getY2();
final double x3 = point.getX();
final double y3 = point.getY();
final double k = ((y2 - y1) * (x3 - x1) - (x2 - x1) * (y3 - y1)) / (Math.pow(y2 - y1, 2) + Math.pow(x2 - x1, 2));
final double x4 = x3 - k * (y2 - y1);
final double y4 = y3 + k * (x2 - x1);
return new Point2D.Double(x4, y4);
}
示例2: isParallel
import java.awt.geom.Line2D; //导入方法依赖的package包/类
/**
*
* @param line1
* @param line2
* @return
*/
public static boolean isParallel(Line2D line1, Line2D line2) {
float x1 = (float) line1.getX1();
float y1 = (float) line1.getY1();
float x2 = (float) line1.getX2();
float y2 = (float) line1.getY2();
float dx = x2 - x1;
float dy = y1 - y2;
float d = (float) Math.sqrt((double) (dx * dx + dy * dy));
float slope1 = Math.abs(dx / d);
x1 = (float) line2.getX1();
y1 = (float) line2.getY1();
x2 = (float) line2.getX2();
y2 = (float) line2.getY2();
dx = x2 - x1;
dy = y1 - y2;
d = (float) Math.sqrt((double) (dx * dx + dy * dy));
float slope2 = Math.abs(dx / d);
return (slope1 == slope2);
}
示例3: extendLine
import java.awt.geom.Line2D; //导入方法依赖的package包/类
/**
* Creates a new line by extending an existing line.
*
* @param line the line (<code>null</code> not permitted).
* @param startPercent the amount to extend the line at the start point
* end.
* @param endPercent the amount to extend the line at the end point end.
*
* @return A new line.
*/
private Line2D extendLine(Line2D line, double startPercent,
double endPercent) {
if (line == null) {
throw new IllegalArgumentException("Null 'line' argument.");
}
double x1 = line.getX1();
double x2 = line.getX2();
double deltaX = x2 - x1;
double y1 = line.getY1();
double y2 = line.getY2();
double deltaY = y2 - y1;
x1 = x1 - (startPercent * deltaX);
y1 = y1 - (startPercent * deltaY);
x2 = x2 + (endPercent * deltaX);
y2 = y2 + (endPercent * deltaY);
return new Line2D.Double(x1, y1, x2, y2);
}
示例4: getIntersectionPoint
import java.awt.geom.Line2D; //导入方法依赖的package包/类
/**
* Gets the intersection point.
*
* @param lineA
* the line a
* @param lineB
* the line b
* @return the intersection point
*/
public static Point2D getIntersectionPoint(final Line2D lineA, final Line2D lineB) {
final double x1 = lineA.getX1();
final double y1 = lineA.getY1();
final double x2 = lineA.getX2();
final double y2 = lineA.getY2();
final double x3 = lineB.getX1();
final double y3 = lineB.getY1();
final double x4 = lineB.getX2();
final double y4 = lineB.getY2();
Point2D p = null;
final double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
if (d != 0) {
final double xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
final double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;
if (xi >= Math.min(lineA.getX1(), lineA.getX2()) && xi <= Math.max(lineA.getX1(), lineA.getX2()) && yi >= Math.min(lineA.getY1(), lineA.getY2()) && yi <= Math.max(lineA.getY1(), lineA.getY2())) {
p = new Point2D.Double(xi, yi);
}
}
return p;
}
示例5: convertBoundsAndSetDropLine
import java.awt.geom.Line2D; //导入方法依赖的package包/类
/** Converts line's bounds by the bounds of the root pane. Drop glass pane
* is over this root pane. After covert a given line is set to drop glass pane.
* @param line line for show in drop glass pane */
private void convertBoundsAndSetDropLine(final Line2D line) {
int x1 = (int) line.getX1();
int x2 = (int) line.getX2();
int y1 = (int) line.getY1();
int y2 = (int) line.getY2();
Point p1 = SwingUtilities.convertPoint(tree, x1, y1, tree.getRootPane());
Point p2 = SwingUtilities.convertPoint(tree, x2, y2, tree.getRootPane());
line.setLine(p1, p2);
if( null != dropPane )
dropPane.setDropLine(line);
}
示例6: convertBoundsAndSetDropLine
import java.awt.geom.Line2D; //导入方法依赖的package包/类
/** Converts line's bounds by the bounds of the root pane. Drop glass pane
* is over this root pane. After covert a given line is set to drop glass pane.
* @param line line for show in drop glass pane */
private void convertBoundsAndSetDropLine(final Line2D line) {
int x1 = (int) line.getX1();
int x2 = (int) line.getX2();
int y1 = (int) line.getY1();
int y2 = (int) line.getY2();
Point p1 = SwingUtilities.convertPoint(table, x1, y1, table.getRootPane());
Point p2 = SwingUtilities.convertPoint(table, x2, y2, table.getRootPane());
line.setLine(p1, p2);
dropPane.setDropLine(line);
}
示例7: renderLightSource
import java.awt.geom.Line2D; //导入方法依赖的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);
}
示例8: getIntersectionPoint
import java.awt.geom.Line2D; //导入方法依赖的package包/类
/**
*
* @param line1
* @param line2
* @param extrapolate
* @return
*/
public static Point2D getIntersectionPoint(Line2D line1, Line2D line2,
boolean extrapolate) {
if (extrapolate || line1.intersectsLine(line2)) {
float x1 = (float) line2.getX1();
float y1 = (float) line2.getY1();
float x2 = (float) line2.getX2();
float y2 = (float) line2.getY2();
float xp1 = (float) line1.getX1();
float yp1 = (float) line1.getY1();
float xp2 = (float) line1.getX2();
float yp2 = (float) line1.getY2();
float y = 0;
float x = 0;
float dy = y2 - y1;
float s = (x2 - x1) / dy;
float dpy = yp2 - yp1;
float sp = (xp2 - xp1) / dpy;
if (y1 == y2) {
if (dpy == 0) {
return null;
}
y = y1;
x = xp1 + sp * (y - yp1);
} else if (yp1 == yp2) {
if (dy == 0) {
return null;
}
y = yp1;
x = x1 + s * (y - y1);
} else {
if (dy == 0 || dpy == 0 || (s - sp) == 0) {
return null;
}
y = (xp1 - x1 + s * y1 - sp * yp1) / (s - sp);
x = x1 + s * (y - y1);
}
return new Point2D.Float(x, y);
}
return null;
}
示例9: isBelow
import java.awt.geom.Line2D; //导入方法依赖的package包/类
/**
* Determines if the given point is below the given line. If the line is perfectly vertical, below is defined as
* being to the right of.
*
* @param line The line
* @param p The point to compare
* @return True if the point is below the line.
*/
public static boolean isBelow(Line2D line, Point p) {
return (line.getX2() - line.getX1()) * (p.y - line.getY1()) - (line.getY2() - line.getY1()) * (p.x - line.getX1()) > 0;
}
示例10: isAbove
import java.awt.geom.Line2D; //导入方法依赖的package包/类
/**
* Determines if the given point is above the given line. If the line is perfectly vertical, above is defined as
* being to the left of.
*
* @param line The line
* @param p The point to compare
* @return True if the point is above the line.
*/
public static boolean isAbove(Line2D line, Point p) {
return (line.getX2() - line.getX1()) * (p.y - line.getY1()) - (line.getY2() - line.getY1()) * (p.x - line.getX1()) < 0;
}