简体   繁体   English

通过圆Javascript行

[英]Line through a Circle Javascript

Trying to draw a line through a Circle 试图通过圆画一条线

eg: https://imgur.com/wk9lAwD 例如: https//imgur.com/wk9lAwD

Here is my code: https://codepen.io/ethan-horrigan/pen/OrRLXx 这是我的代码: https : //codepen.io/ethan-horrigan/pen/OrRLXx

    var r = 200;
    var x1 = 800 / 2;
    var y1 = 540 / 2;

    var x = r * Math.cos(Math.PI / 180 * 135) + x1;
    var y = r * Math.sin(Math.PI / 180 * 315) + y1;

    ctx.beginPath();
    ctx.arc(x1, y1, r, 0, Math.PI * 2, false);

    ctx.moveTo(x1,y1);
    ctx.lineTo(x, y);
    ctx.stroke();

I believe this is what you want: 我相信这就是您想要的:

ctx.moveTo(x, y);
ctx.lineTo(x1 + (x1 - x), y1 + (y1 - y));
ctx.stroke();

Codepen Codepen

var r = 200;
var x1 = 800 / 2;
var y1 = 540 / 2;

var x = r * Math.cos(Math.PI * .75) + x1;
var y = r * Math.sin(Math.PI * 1.75) + y1;
ctx.beginPath();
ctx.arc(x1, y1, r, Math.PI * .25, Math.PI * 2.25, false);

ctx.lineTo(x, y);
ctx.stroke();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM