COGO: Finding centre and radius of a curve defined by three points: FindCircle function

Recently I had need to convert a PL/SQL Oracle Spatial function I created years ago called FindCircle to SQL Server 2008 for use in another project. That function was original work already released to the public domain as part of my free COGO package for Oracle. Here is that function for SQL Server.

Note that I have a schema call cogo in which I create functions like this. You can use anything you like.

 /** ----------------------------------------------------------------------------------------   * @function   : FindCircle
   * @precis     : Function that determines if three points form a circle. If so a table containing   *               centre and radius is returned. If not, a null table is returned.   * @version    : 1.0
   * @usage      : Function FindCircle(@p_X1 float, @p_Y1 float,
   *                                    @p_X2 float, @p_Y2 float,
   *                                    @p_X3 float, @p_Y3 float )
   *                Returns @circle table ([cx]     float,
   *                                       [cy]     float,
   *                                       [radius] float )
   *               eg select c.cx, c.cy, c.radius
   *                    from [FindCircle](0.0,0.0,10.0,0.0,10.0,10.0) c;
   * @param      : p_X1/p_Y1    : First point in curve
   * @param      : p_X2/p_Y2    : Second point in curve
   * @param      : p_X3/p_Y3    : Third point in curve
   * @return    : cx/cy/radius : Centre X, Y and radius of found circle or NULL if three points do not form a circle.
   * @history    : Simon Greener - May 2011 - Original coding.
   * @copyright  : Licensed under a Creative Commons Attribution-Share Alike 2.5 Australia License. (http://creativecommons.org/licenses/by-sa/2.5/au/) **/
 CREATE FUNCTION cogo.FindCircle(@p_X1 FLOAT, @p_Y1 FLOAT,
                                 @p_X2 FLOAT, @p_Y2 FLOAT,
                                 @p_X3 FLOAT, @p_Y3 FLOAT )
 RETURNS @circle TABLE (
       [cx]     FLOAT,
       [cy]     FLOAT,
       [radius] FLOAT
 )
 etc

The function can be used as follows:

 SELECT c.cx, c.cy, c.radius
   FROM cogo.FindCircle(0.0,0.0,10.0,0.0,10.0,10.0) c;

|_. cx|_. cy|_. radius| |5|5|7.07106781186548| If anyone would like the source code for this function, please contact me directly. Simon