KiCad PCB EDA Suite
lib_arc.cpp File Reference
#include <fctsys.h>
#include <gr_basic.h>
#include <macros.h>
#include <class_drawpanel.h>
#include <plot_common.h>
#include <trigo.h>
#include <wxstruct.h>
#include <richio.h>
#include <base_units.h>
#include <msgpanel.h>
#include <bitmaps.h>
#include <general.h>
#include <lib_arc.h>
#include <transform.h>

Go to the source code of this file.

Functions

static wxPoint twoPointVector (const wxPoint &startPoint, const wxPoint &endPoint)
 
static wxPoint calcCenter (const wxPoint &A, const wxPoint &B, const wxPoint &C)
 Given three points A B C, compute the circumcenter of the resulting triangle reference: http://en.wikipedia.org/wiki/Circumscribed_circle Coordinates of circumcenter in Cartesian coordinates. More...
 

Function Documentation

static wxPoint calcCenter ( const wxPoint A,
const wxPoint B,
const wxPoint C 
)
static

Given three points A B C, compute the circumcenter of the resulting triangle reference: http://en.wikipedia.org/wiki/Circumscribed_circle Coordinates of circumcenter in Cartesian coordinates.

Definition at line 55 of file lib_arc.cpp.

References D, wxPoint::x, and wxPoint::y.

Referenced by LIB_ARC::calcEdit().

56 {
57  double circumCenterX, circumCenterY;
58  double Ax = (double) A.x;
59  double Ay = (double) A.y;
60  double Bx = (double) B.x;
61  double By = (double) B.y;
62  double Cx = (double) C.x;
63  double Cy = (double) C.y;
64 
65  wxPoint circumCenter;
66 
67  double D = 2.0 * ( Ax * ( By - Cy ) + Bx * ( Cy - Ay ) + Cx * ( Ay - By ) );
68 
69  // prevent division / 0
70  if( fabs( D ) < 1e-7 )
71  D = 1e-7;
72 
73  circumCenterX = ( (Ay * Ay + Ax * Ax) * (By - Cy) +
74  (By * By + Bx * Bx) * (Cy - Ay) +
75  (Cy * Cy + Cx * Cx) * (Ay - By) ) / D;
76 
77  circumCenterY = ( (Ay * Ay + Ax * Ax) * (Cx - Bx) +
78  (By * By + Bx * Bx) * (Ax - Cx) +
79  (Cy * Cy + Cx * Cx) * (Bx - Ax) ) / D;
80 
81  circumCenter.x = (int) circumCenterX;
82  circumCenter.y = (int) circumCenterY;
83 
84  return circumCenter;
85 }
#define D(x)
Definition: ptree.cpp:41
static wxPoint twoPointVector ( const wxPoint startPoint,
const wxPoint endPoint 
)
inlinestatic

Definition at line 46 of file lib_arc.cpp.

Referenced by LIB_ARC::BeginEdit(), LIB_ARC::calcEdit(), LIB_ARC::calcRadiusAngles(), and LIB_ARC::HitTest().

47 {
48  return endPoint - startPoint;
49 }