public static Coordinate[] computeTangentsThroughPoint(Coordinate circleCenter,double radius,Coordinate point){
  Coordinate[] ret=new Coordinate[3];
  double dx=(point.x - circleCenter.x) / 2;
  double dy=(point.y - circleCenter.y) / 2;
  double d=Math.sqrt(dx * dx + dy * dy);
  double a=(radius * radius) / (2.0 * d);
  double x2=circleCenter.x + (dx * a / d);
  double y2=circleCenter.y + (dy * a / d);
  double h=Math.sqrt(radius * radius - a * a);
  double rx=-dy * (h / d);
  double ry=dx * (h / d);
  double xi=x2 + rx;
  double yi=y2 + ry;
  double xiPrime=x2 - rx;
  double yiPrime=y2 - ry;
  ret[0]=new Coordinate(point);
  ret[1]=new Coordinate(xi,yi);
  ret[2]=new Coordinate(xiPrime,yiPrime);
  return ret;
}

public static Coordinate [ ] computeTangentsThroughPoint ( Coordinate circleCenter , double radius , Coordinate point ) { Coordinate [ ] ret = new Coordinate [ 3 ] ; double dx = ( point . x - circleCenter . x ) / 2 ; double dy = ( point . y - circleCenter . y ) / 2 ; double d = Math . sqrt ( dx * dx + dy * dy ) ; double a = ( radius * radius ) / ( 2.0 * d ) ; double x2 = circleCenter . x + ( dx * a / d ) ; double y2 = circleCenter . y + ( dy * a / d ) ; double h = Math . sqrt ( radius * radius - a * a ) ; double rx = - dy * ( h / d ) ; double ry = dx * ( h / d ) ; double xi = x2 + rx ; double yi = y2 + ry ; double xiPrime = x2 - rx ; double yiPrime = y2 - ry ; ret [ 0 ] = new Coordinate ( point ) ; ret [ 1 ] = new Coordinate ( xi , yi ) ; ret [ 2 ] = new Coordinate ( xiPrime , yiPrime ) ; return ret ; }
computes both tangents of a circle running through a given point . computation uses thales ' theorem . note the point has to be outside the circle . this requirement , however , will not be checked !
