I am trying to create an arrow using line and triangle shapes. You can check the demo on jsbin:
http://jsbin.com/xuyere/1/edit?js,output
As you can see from the demo that arrow head's position varies with angle and it's not correct. What am I doing wrong here?
Here's the math I used to calculate angle:
var dx = x2 - x1,
dy = y2 - y1,
angle = Math.atan2(dy, dx);
angle *= 180 / Math.PI;
angle += 90;
I have changed the value of centerX and CenterY to center and its coming perfectly. Updated code should look like this. Your updated code http://jsbin.com/nepiqaviqe/1/edit?js,output
var triangle = new fabric.Triangle({
angle: angle,
fill: '#207cca',
top: y2,
left: x2,
height: headLength,
width: headLength,
originX: 'center',
originY: 'center',
selectable: false
});
fCanvas.add(triangle);
}
function createLineArrow(points) {
var line = new fabric.Line(points, {
strokeWidth: 5,
stroke: '#7db9e8',
originX: 'center',
originY: 'center',
hasControls: false,
hasBorders: false,
hasRotatingPoint: false,
hoverCursor: 'default',
selectable: false
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With