Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

24
LINES

< > TinyBrain | #1007301 - drawArrowHead

JavaX fragment (include)

import java.awt.geom.*;

static float drawArrowHead_length = 2f;

static void drawArrowHead(Graphics2D g, double x1, double y1, double x2, double y2, double size) {
  if (y2 == y1 && x2 == x1) ret;
  
  Path2D.Double arrowHead = new Path2D.Double();
  arrowHead.moveTo(0, 0);
  double l = drawArrowHead_length*size;
  arrowHead.lineTo(-size, -l);
  arrowHead.lineTo(size, -l);
  arrowHead.closePath();

  new AffineTransform tx;
  double angle = Math.atan2(y2-y1, x2-x1);
  tx.translate(x2, y2);
  tx.rotate(angle-Math.PI/2d);

  AffineTransform old = g.getTransform();
  g.transform(tx);
  g.fill(arrowHead);
  g.setTransform(old);
}

download  show line numbers  debug dex   

Travelled to 2 computer(s): cfunsshuasjs, tvejysmllsmz

No comments. add comment

Snippet ID: #1007301
Snippet name: drawArrowHead
Eternal ID of this version: #1007301/16
Text MD5: 035e9e7409200b67b93ed44e90e49ab5
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-24 01:49:40
Source code size: 657 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 67 / 59
Version history: 15 change(s)
Referenced in: [show]