title: Drawing a line within boundaries from point (x, y) with a given angle
body: <p>I am trying to draw a line on JavaScript canvas. I have two points A and B (as shown in the picture).</p>
  
  <p><a href="https://i.stack.imgur.com/fHww6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fHww6.png" alt="Points A and B"></a></p>
  
  <p>I use this code to find the angle between these two points:</p>
  
  <pre><code>// p1 is point A and p2 is point B    
  var theta = Math.atan2(p2.y - p1.y, p2.x - p1.x);
  </code></pre>
  
  <p>Now I want to draw a line from point A till the end of the canvas and I also want to get the point where the line ends (point C in the picture).</p>
  
  <p><a href="https://i.stack.imgur.com/xIR1u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xIR1u.png" alt="enter image description here"></a></p>
  
  <p>Can this be achieved using the angle and size(width &amp; height) of the canvas?</p>