最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Arrow shape using FabricJS - Stack Overflow

programmeradmin0浏览0评论

I am trying to create an arrow using line and triangle shapes. You can check the demo on jsbin:

,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 am trying to create an arrow using line and triangle shapes. You can check the demo on jsbin:

http://jsbin./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;
Share Improve this question asked Apr 27, 2015 at 8:03 ifadeyifadey 1,06210 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

I have changed the value of centerX and CenterY to center and its ing perfectly. Updated code should look like this. Your updated code http://jsbin./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
 });
发布评论

评论列表(0)

  1. 暂无评论