【发布时间】:2020-12-04 01:11:51
【问题描述】:
我正在尝试将两个矩形绘制为一个形状,并使用 HTML5 画布包含角度注释。
我想要实现的最终版本是这样的:
如何找到内角的交点以知道在哪里绘制角度注释?
let canvas=document.getElementById("canvas");
let ctx=canvas.getContext("2d");
// rectangle dimensions
let height = 50;
let width = 200;
// starting coordinates
let x = 20;
let y = 20;
// translate to starting coordinates
ctx.translate(x, y);
// draw first rectangle
ctx.strokeRect(0,0,width,height);
// translate to the end of the first rectangle
ctx.translate(width, 0);
// rotate canvas by 45 degrees
ctx.rotate(45 * Math.PI / 180);
// draw second rectangle
ctx.strokeRect(0,0,width,height);
<!doctype html>
<html>
<head>
<style>
body{ background-color: rgb(255, 255, 255); }
</style>
</head>
<body>
<canvas id="canvas" width=700 height=500></canvas>
</body>
</html>
【问题讨论】:
-
你没有在你的代码上尝试太多 sn-p... 把这个问题分解成线,一个矩形只有 4 条线,它们的交点是基本几何:topcoder.com/community/competitive-programming/tutorials/…
标签: canvas geometry html5-canvas