dia r3987 - in trunk: . lib



Author: hans
Date: Sun May  4 11:56:49 2008
New Revision: 3987
URL: http://svn.gnome.org/viewvc/dia?rev=3987&view=rev

Log:
2008-05-04  Hans Breuer  <hans breuer org>

	* lib/geometry.[hc] lib/libdia.def: three_point_circle() calculate
	center point and radius given 3 points on a circle



Modified:
   trunk/ChangeLog
   trunk/lib/geometry.c
   trunk/lib/geometry.h
   trunk/lib/libdia.def

Modified: trunk/lib/geometry.c
==============================================================================
--- trunk/lib/geometry.c	(original)
+++ trunk/lib/geometry.c	Sun May  4 11:56:49 2008
@@ -702,6 +702,31 @@
   *aa = stop_angle;
 }
 
+int 
+three_point_circle (const Point *p1, const Point *p2, const Point *p3,
+                    Point* center, real* radius)
+{
+  const real epsilon = 1e-4;
+  real x1 = p1->x;
+  real y1 = p1->y;
+  real x2 = p2->x;
+  real y2 = p2->y;
+  real x3 = p3->x;
+  real y3 = p3->y;
+  real ma, mb;
+  if (fabs(x2 - x1) < epsilon)
+    return 0;
+  if (fabs(x3 - x2) < epsilon)
+    return 0;
+  ma = (y2 - y1) / (x2 - x1);
+  mb = (y3 - y2) / (x3 - x2);
+  if (fabs (mb - ma) < epsilon)
+    return 0;
+  center->x = (ma*mb*(y1-y3)+mb*(x1+x2)-ma*(x2+x3))/(2*(mb-ma));
+  center->y = ma*(center->x - x1) + y1;
+  *radius = distance_point_point(center, p1);
+  return 1;
+}
 
 
 /* moved this here since it is being reused by rounded polyline code*/

Modified: trunk/lib/geometry.h
==============================================================================
--- trunk/lib/geometry.h	(original)
+++ trunk/lib/geometry.h	Sun May  4 11:56:49 2008
@@ -362,6 +362,8 @@
 void point_perp(Point *p, real a, real b, real c, Point *perp);
 void fillet(Point *p1, Point *p2, Point *p3, Point *p4,
 	    real r, Point *c, real *pa, real *aa);
+int  three_point_arc(const Point *p1, const Point *p2, const Point *p3,
+                     Point* center, real* radius);
 real point_cross(Point *p1, Point *p2);
 Point calculate_object_edge(Point *objmid, Point *end, DiaObject *obj);
 

Modified: trunk/lib/libdia.def
==============================================================================
--- trunk/lib/libdia.def	(original)
+++ trunk/lib/libdia.def	Sun May  4 11:56:49 2008
@@ -565,6 +565,7 @@
  transform_point
 
  point_get_perp
+ three_point_circle
 
  polybezier_bbox
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]