N
N
Nikita Podosenov2020-04-06 13:28:30
JavaScript
Nikita Podosenov, 2020-04-06 13:28:30

How to draw a line in canvas at an angle, knowing the length?

Is there any function in canvas to be able to draw a line at an angle of the desired length?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2020-04-06
@prizmer

function drawMyLine(x,y,angleDeg,length){//Угол в градусах
  var angle = angleDeg * Math.PI/180;
  ctx.beginPath();
  ctx.moveTo(x,y);
  ctx.lineTo(x + Math.cos(angle)*length,y + Math.sin(angle)*length);  
  ctx.stroke();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question