Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw in arrow on a web browser

Tags:

html

jquery

Given two point, (x, y) and (x1, y1), how do I draw an arrow between these point a the web browser. Can jQuery or HTML5 does this?

like image 520
Thang Pham Avatar asked Feb 04 '26 13:02

Thang Pham


1 Answers

You'll also need a little high school trigonometry to draw the arrowhead.

var arrowHeadLength = 10; //whatever arbitrary value you want
// Line angle
var lineAngle = Math.atan ( (Y2-Y1)/(X2-X1) )
// Angle for arrow heads
var end1 = lineAngle + 45 * Math.PI/180
var end2 = lineAngle - 45 * Math.PI/180
// end points of arrow heads
var y3 = y2 - arrowHeadLength * Math.sin(end1)
var x3 = x2 - arrowHeadLength * Math.cos(end1)
var y4 = y2 - arrowHeadLength * Math.sin(end2)
var x4 = x2 - arrowHeadLength * Math.cos(end2)
like image 184
JaredMcAteer Avatar answered Feb 06 '26 08:02

JaredMcAteer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!