Skip to content

Instantly share code, notes, and snippets.

@UnVoiding
UnVoiding / TangentToCircle
Last active August 29, 2015 14:14
Canvas arc. Tangent from point to circle.
function TangentToCircle(fromx, fromy, cx, cy, r) {
var canvas = document.getElementById('canvas1');
var context = canvas.getContext('2d');
var fi = 0;
context.beginPath();
if (fromx != cx && fromy != cy) {
var length = Math.sqrt(Math.pow(fromx - cx, 2) + Math.pow(fromy - cy, 2));
var a = Math.atan(r/length);