KiCad PCB EDA Suite
lib_arc.cpp File Reference
#include <fctsys.h>
#include <gr_basic.h>
#include <macros.h>
#include <class_drawpanel.h>
#include <class_plotter.h>
#include <trigo.h>
#include <wxstruct.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 54 of file lib_arc.cpp.

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

Referenced by LIB_ARC::calcEdit().

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

Definition at line 45 of file lib_arc.cpp.

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

46 {
47  return endPoint - startPoint;
48 }