h5画三角形_<html5>围绕圆圈画三角形

这篇博客探讨了如何在HTML5中实现点击矩形后,在圆形周围精确绘制三角形的问题。作者分享了源代码,并提出通过计算三角形到圆心的最短距离来定位三角形的方法。
摘要由CSDN通过智能技术生成

我想要点击retacgle,在圆圈周围绘制一个三角形。围绕圆圈画三角形

源代码是这样的...

但是,三角并不好每个位置..

怎样绘制周围像附加的图像圆三角形...

....

....

ost = 30515;

oen = 31570;

//ost = 74147;

//oen = 75664;

color="255,0,0";

av = (ost+oen) /2 ;

x1 = centerX-radius*Math.sin(-arg*av);

y1 = centerY-radius*Math.cos(-arg*av);

x2 = centerX-radius*Math.sin(-arg*av)*1.07;

y2 = centerY-radius*Math.cos(-arg*av)*1.07;

var s={x1:x1,y1:y1,x2:x2,y2:y2};

triShape(s,color,true);

...

...

//绘制由retacgle圆圈

function Shape_sub(s, k, color, draw){

ctx_sub.save();

//ctx_sub.rotate(Math.PI * 2/12);

ctx_sub.fillStyle='rgb('+color+')';

ctx_sub.imageSmoothingEnabled = true;

ctx_sub.beginPath();

ctx_sub.moveTo(s.x1,s.y1);

ctx_sub.lineTo(s.x2,s.y2);

ctx_sub.lineTo(s.x3,s.y3);

ctx_sub.lineTo(s.x4,s.y4);

ctx_sub.lineTo(s.x1,s.y1);

if(draw){

ctx_sub.fill();

ctx_sub.stroke();

}

ctx_sub.restore();

}

//绘制围绕圆的三角形 - >但不运行....

function triShape(s,color,draw){

ctx_sub.save();

//ctx_sub.rotate(Math.PI * 2/12);

ctx_sub.fillStyle='rgb('+color+')';

ctx_sub.imageSmoothingEnabled = true;

ctx_sub.beginPath();

ctx_sub.moveTo(s.x1,s.y1);

ctx_sub.lineTo(s.x1,s.y1);

ctx_sub.lineTo(s.x2,s.y2);

if(draw){

ctx_sub.fill();

ctx_sub.stroke();

}

ctx_sub.restore();

}

..

....

+0

你可以尝试从三角形到圆心的一个点计算长度,保持旋转的三角形,直到你找到最短距离。为了定位三角形,只需搜索一个位置 –

2014-08-28 01:10:42

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值