import java.awt.*; import java.awt.geom.Line2D; import javax.swing.*; public class FrameTest { public static void main(String[] args) { JFrame jf = new JFrame("Demo"); Container cp = jf.getContentPane(); cp.add(new JComponent() { public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(10)); g2.draw(new Line2D.Float(30, 20, 80, 90)); } }); jf.setSize(300, 200); jf.setVisible(true); } }
g.draw ( new Line2D.Float ( 50.0f, 0.0f, veeX, 0.0f ) ); g.draw ( new Line2D.Float ( 50.0f, 0.0f, veeX - stroke.getLineWidth() * 0.25f, 0.0f ) ); g.draw ( new Line2D.Float ( 50.0f, 0.0f, veeX - arrowLength * 0.5f, 0.0f ) );
Line2D line1 = new Line2D.Float(100, 100, 200, 200); Line2D line2 = new Line2D.Float(150, 150, 150, 200); boolean result = line2.intersectsLine(line1); System.out.println(result); // => true // Also check out linesIntersect() if you do not need to construct the line objects // It will probably be faster due to putting less pressure on the garbage collector // if running it in a loop System.out.println(Line2D.linesIntersect(100,100,200,200,150,150,150,200));
/** * Draws a line, using the current color, between the points * <code>(x1, y1)</code> and <code>(x2, y2)</code> * in this graphics context's coordinate system. * @param x1 the first point's <i>x</i> coordinate. * @param y1 the first point's <i>y</i> coordinate. * @param x2 the second point's <i>x</i> coordinate. * @param y2 the second point's <i>y</i> coordinate. */ public void drawLine(int x1, int y1, int x2, int y2) { Line2D line = new Line2D.Float(x1, y1, x2, y2); draw(line); }
static void drawLine(Graphics2D g, RoadMapping roadMapping, double position, int strokeWidth, Color color) { Color prevColor = g.getColor(); final double lateralExtend = roadMapping.getLaneCountInDirection() * roadMapping.laneWidth(); final PosTheta posTheta = roadMapping.map(position, 0/* offset */); final PolygonFloat line = roadMapping.mapLine(posTheta, roadMapping.isPeer() ? +lateralExtend : -lateralExtend); g.setColor(color); g.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); g.draw(new Line2D.Float(line.getXPoint(0), line.getYPoint(0), line.getXPoint(1), line.getYPoint(1))); g.setColor(prevColor); }
@Override public void lineTo(float x1, float y1) throws IOException { Point2D.Float newPoint = transformPoint(x1, y1); lines.add(new Line2D.Float(currentPoint, newPoint)); currentPoint = newPoint; }
/** * Draws a straight line from (x1,y1) to (x2,y2). */ public void drawLine(int x1, int y1, int x2, int y2) { Shape shape = new Line2D.Float(x1, y1, x2, y2); draw(shape); }
public static void main(String[] args) { Rectangle rectangle = new Rectangle(0,0,10,10); Line2D line = new Line2D.Float(4,4,5,5); System.err.println(""+new Intersector(rectangle, line)); System.err.println(""+new Intersector(rectangle, new Line2D.Float(9,11,11,9))); System.err.println(""+new Intersector(rectangle, new Line2D.Float(1,1,3,2))); System.err.println(""+new Intersector(rectangle, new Line2D.Float(4,6,6,4))); }
protected void build() throws SVGException { super.build(); StyleAttribute sty = new StyleAttribute(); if (getPres(sty.setName("x1"))) x1 = sty.getFloatValueWithUnits(); if (getPres(sty.setName("y1"))) y1 = sty.getFloatValueWithUnits(); if (getPres(sty.setName("x2"))) x2 = sty.getFloatValueWithUnits(); if (getPres(sty.setName("y2"))) y2 = sty.getFloatValueWithUnits(); line = new Line2D.Float(x1, y1, x2, y2); }
public static void main(String[] args) { Rectangle rectangle = new Rectangle(0, 0, 10, 10); Line2D line = new Line2D.Float(4, 4, 5, 5); System.err.println("" + new Intersector(rectangle, line)); System.err.println("" + new Intersector(rectangle, new Line2D.Float(9, 11, 11, 9))); System.err.println("" + new Intersector(rectangle, new Line2D.Float(1, 1, 3, 2))); System.err.println("" + new Intersector(rectangle, new Line2D.Float(4, 6, 6, 4))); } }
if(shape1==shape2 && shape2==shape3){ public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; Line2D lin = new Line2D.Float(100, 100, 250, 260); g2.draw(lin); } }
@Override public boolean detectCollision(final Point p) { final CollisionDetector collisionDetector = new CollisionDetector(); for (int i = 1; i < xs.length; i++) { if (collisionDetector.detectCollision(p, new Line2D.Float(xs[i - 1], ys[i - 1], xs[i], ys[i]))) { return true; } } return false; }
@Override public boolean detectCollision(final Point p) { final Line2D line = new Line2D.Float(start, end); return new CollisionDetector().detectCollision(p, line); } }
/** * Draws a line, using the current color, between the points <code>(x1, y1)</code> and <code>(x2, y2)</code> * in this graphics context's coordinate system. * * @param x1 the first point's <i>x</i> coordinate. * @param y1 the first point's <i>y</i> coordinate. * @param x2 the second point's <i>x</i> coordinate. * @param y2 the second point's <i>y</i> coordinate. */ public void drawLine( final int x1, final int y1, final int x2, final int y2 ) { parent.draw( new Line2D.Float( x1, y1, x2, y2 ) ); }
/** * Draw a line */ public static boolean imageline(QuercusImage image, int x1, int y1, int x2, int y2, int color) { image.stroke(new Line2D.Float(x1, y1, x2, y2), color); return true; }
private void drawTick(Graphics2D g2, float x, float y, double val) { g2.draw(new Line2D.Float(x, y, x + TICK_LENGTH, y)); FontMetrics fm = g2.getFontMetrics(); g2.drawString(Double.toString(val), x + TICK_LENGTH + 1.0f, y + fm.getAscent() - fm.getHeight() * 0.5f); }
@Override public boolean detectCollision(final Point p) { final CollisionDetector collisionDetector = new CollisionDetector(); for (int i = 1; i < xs.length; i++) { if (collisionDetector.detectCollision(p, new Line2D.Float(xs[i - 1], ys[i - 1], xs[i], ys[i]))) { return true; } } return false; } }
@Override public Line2D.Float transformLine(int x1, int y1, int x2, int y2) { return new Line2D.Float(x2, Math.abs(y2), x1, Math.abs(y1)); } }
line = pc.compare(start_pos, end_pos) == -1 ? new Line2D.Float(start_pos, end_pos) : new Line2D.Float(end_pos, start_pos); break; line = pc.compare(end_pos, last_move) == -1 ? new Line2D.Float(end_pos, last_move) : new Line2D.Float(last_move, end_pos);
switch (code) { case PathIterator.SEG_LINETO: return new Line2D.Float(x1, y1, buffer[0], buffer[1]); case PathIterator.SEG_QUADTO: return new QuadCurve2D.Float(