如何在圆内绘制三角形指针

问题描述 投票:0回答:1

我意识到这是一个简单的三角学问题,但是我的高中现在使我不及格。

给出一个角度,我已将其转换为弧度以获得第一个点。如何计算三角形的下两个点以在画布上绘制,以便使小三角形始终指向圆。因此,可以说我已经画了一个给定半径的圆。现在,我想要一个函数来绘制一个三角形,该三角形位于其内部圆的边缘上,无论角度如何,该三角形都朝外。 (可以这么说)

function drawPointerTriangle(ctx, angle){
    var radians = angle * (Math.PI/180)
    var startX = this.radius + this.radius/1.34 * Math.cos(radians)
    var startY = this.radius - this.radius/1.34 * Math.sin(radians)
    // This gives me my starting point on the outer edge of the circle, plotted at the angle I need    
    ctx.moveTo(startX, startY);

   // HOW DO I THEN CALCULATE x1,y1 and x2, y2.  So that no matter what angle I enter into this function, the arrow/triangle always points outwards to the circle.
    ctx.lineTo(x1, y1);
    ctx.lineTo(x2, y2);


}

示例enter image description here

我意识到这是一个简单的三角学问题,但是我的高中现在使我不及格。给定一个角度,我已将其转换为弧度以获得第一点。如何计算下一个...

javascript html canvas trigonometry
1个回答
0
投票

减小半径,更改角度,然后再次调用cos / sin:

© www.soinside.com 2019 - 2024. All rights reserved.