![]() |
KiCad PCB EDA Suite
|
Trigonometric and geometric basic functions. More...
#include <limits>
#include <stdlib.h>
#include <type_traits>
#include <geometry/seg.h>
#include <math/util.h>
#include <math/vector2d.h>
#include <trigo.h>
Go to the source code of this file.
Functions | |
bool | IsPointOnSegment (const wxPoint &aSegStart, const wxPoint &aSegEnd, const wxPoint &aTestPoint) |
Test if aTestPoint is on line defined by aSegStart and aSegEnd. More... | |
bool | SegmentIntersectsSegment (const wxPoint &a_p1_l1, const wxPoint &a_p2_l1, const wxPoint &a_p1_l2, const wxPoint &a_p2_l2, wxPoint *aIntersectionPoint) |
Test if two lines intersect. More... | |
bool | TestSegmentHit (const wxPoint &aRefPoint, const wxPoint &aStart, const wxPoint &aEnd, int aDist) |
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd. More... | |
const VECTOR2I | CalcArcMid (const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aMinArcAngle) |
Return the middle point of an arc, half-way between aStart and aEnd. More... | |
double | ArcTangente (int dy, int dx) |
void | RotatePoint (int *pX, int *pY, double angle) |
void | RotatePoint (int *pX, int *pY, int cx, int cy, double angle) |
void | RotatePoint (wxPoint *point, const wxPoint ¢re, double angle) |
void | RotatePoint (VECTOR2I &point, const VECTOR2I ¢re, double angle) |
void | RotatePoint (double *pX, double *pY, double cx, double cy, double angle) |
void | RotatePoint (double *pX, double *pY, double angle) |
const VECTOR2D | CalcArcCenter (const VECTOR2D &aStart, const VECTOR2D &aEnd, double aAngle) |
const VECTOR2D | CalcArcCenter (const VECTOR2D &aStart, const VECTOR2D &aMid, const VECTOR2D &aEnd) |
const VECTOR2I | CalcArcCenter (const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd) |
Determine the center of an arc or circle given three points on its circumference. More... | |
const wxPoint | CalcArcCenter (const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd) |
double | CalcArcAngle (const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd) |
Return the subtended angle for a given arc. More... | |
Trigonometric and geometric basic functions.
Definition in file trigo.cpp.
double ArcTangente | ( | int | dy, |
int | dx | ||
) |
Definition at line 183 of file trigo.cpp.
References RAD2DECIDEG().
Referenced by BuildCornersList_S_Shape(), LIB_SHAPE::CalcArcAngles(), CalcArcMid(), EDA_SHAPE::calcEdit(), EDA_SHAPE::computeArcBBox(), AM_PRIMITIVE::ConvertShapeToPolygon(), AR_MATRIX::drawSegmentQcq(), fillArcPOLY(), PCB_ARC::GetAngle(), SCH_LINE::GetAngleFrom(), PCB_ARC::GetArcAngleEnd(), PCB_ARC::GetArcAngleStart(), SHAPE_ARC::GetCentralAngle(), CADSTAR_SCH_ARCHIVE_LOADER::getPolarAngle(), CADSTAR_PCB_ARCHIVE_LOADER::getPolarAngle(), SCH_LINE::GetReverseAngleFrom(), GRCSegm(), PCB_ARC::HitTest(), DSN::SPECCTRA_DB::makeIMAGE(), PCAD2KICAD::PCB_ARC::Parse(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), BRDITEMS_PLOTTER::PlotPcbShape(), PLOTTER::segmentAsOval(), SHAPE_ARC::SHAPE_ARC(), and AR_MATRIX::traceArc().
Return the subtended angle for a given arc.
Definition at line 567 of file trigo.cpp.
References PNS::angle(), VECTOR2< T >::Angle(), CalcArcCenter(), RAD2DECIDEG(), RotatePoint(), v2, VECTOR2< T >::x, and VECTOR2< T >::y.
Definition at line 362 of file trigo.cpp.
References EuclideanNorm(), r, VECTOR2< T >::Resize(), and VECTOR2< T >::Rotate().
Referenced by CalcArcAngle(), and CalcArcCenter().
const VECTOR2D CalcArcCenter | ( | const VECTOR2D & | aStart, |
const VECTOR2D & | aMid, | ||
const VECTOR2D & | aEnd | ||
) |
Definition at line 390 of file trigo.cpp.
References VECTOR2< T >::EuclideanNorm(), VECTOR2< T >::x, and VECTOR2< T >::y.
const VECTOR2I CalcArcCenter | ( | const VECTOR2I & | aStart, |
const VECTOR2I & | aMid, | ||
const VECTOR2I & | aEnd | ||
) |
Determine the center of an arc or circle given three points on its circumference.
aStart | The starting point of the circle (equivalent to aEnd) |
aMid | The point on the arc, half-way between aStart and aEnd |
aEnd | The ending point of the circle (equivalent to aStart) |
Definition at line 525 of file trigo.cpp.
References CalcArcCenter(), KiROUND(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by SHAPE_ARC::ConstructFromStartEndAngle(), SHAPE_ARC::GetCenter(), PCB_ARC::GetPosition(), PCB_ARC::GetRadius(), CONVERT_TOOL::SegmentToArc(), EDA_SHAPE::SetArcGeometry(), FP_SHAPE::SetArcGeometry0(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), and DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate().
const wxPoint CalcArcCenter | ( | const wxPoint & | aStart, |
const wxPoint & | aMid, | ||
const wxPoint & | aEnd | ||
) |
Definition at line 546 of file trigo.cpp.
References CalcArcCenter(), KiROUND(), VECTOR2< T >::x, and VECTOR2< T >::y.
const VECTOR2I CalcArcMid | ( | const VECTOR2I & | aStart, |
const VECTOR2I & | aEnd, | ||
const VECTOR2I & | aCenter, | ||
bool | aMinArcAngle = true |
||
) |
Return the middle point of an arc, half-way between aStart and aEnd.
There are two possible solutions which can be found by toggling aMinArcAngle. The behaviour is undefined for semicircles (i.e. 180 degree arcs).
aStart | The starting point of the arc (for calculating the radius) |
aEnd | The end point of the arc (for determining the arc angle) |
aCenter | The center point of the arc |
aMinArcAngle | If true, returns the point that results in the smallest arc angle. |
Definition at line 163 of file trigo.cpp.
References ArcTangente(), NormalizeAngle180(), RotatePoint(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by CIRCLE::ConstructFromTanTanPt(), EDIT_TOOL::DragArcTrack(), and SCH_EAGLE_PLUGIN::loadSymbolWire().
bool IsPointOnSegment | ( | const wxPoint & | aSegStart, |
const wxPoint & | aSegEnd, | ||
const wxPoint & | aTestPoint | ||
) |
Test if aTestPoint is on line defined by aSegStart and aSegEnd.
This function is faster than TestSegmentHit() because aTestPoint should be exactly on the line. This works fine only for H, V and 45 degree line segments.
aSegStart | The first point of the line segment. |
aSegEnd | The second point of the line segment. |
aTestPoint | The point to test. |
Definition at line 42 of file trigo.cpp.
Referenced by SCH_LINE_WIRE_BUS_TOOL::AddJunctionsIfNeeded(), SCH_EDIT_FRAME::BreakSegments(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), SCH_LINE_WIRE_BUS_TOOL::TrimOverLappingWires(), SCH_EDIT_FRAME::TrimWire(), SCH_BUS_WIRE_ENTRY::UpdateDanglingState(), and SCH_BUS_BUS_ENTRY::UpdateDanglingState().
void RotatePoint | ( | int * | pX, |
int * | pY, | ||
double | angle | ||
) |
Definition at line 229 of file trigo.cpp.
References PNS::angle(), DECIDEG2RAD(), KiROUND(), and NORMALIZE_ANGLE_POS().
Referenced by CADSTAR_PCB_ARCHIVE_LOADER::addAttribute(), PCAD2KICAD::PCB_FOOTPRINT::AddToBoard(), PCAD2KICAD::PCB_PAD::AddToFootprint(), CADSTAR_SCH_ARCHIVE_LOADER::applyTransform(), SVG_PLOTTER::Arc(), BuildConvexHull(), BuildCornersList_S_Shape(), PAD::BuildEffectiveShapes(), CalcArcAngle(), CalcArcMid(), EDA_SHAPE::calcEdit(), PSLIKE_PLOTTER::computeTextParameters(), SHAPE_ARC::ConstructFromStartEndAngle(), SHAPE_ARC::ConstructFromStartEndCenter(), ConvertOutlineToPolygon(), AM_PRIMITIVE::ConvertShapeToPolygon(), D_CODE::ConvertShapeToPolygon(), CornerListToPolygon(), PCAD2KICAD::CorrectTextPosition(), EXCELLON_WRITER::createDrillFile(), MICROWAVE_TOOL::createFootprint(), SCH_GLOBALLABEL::CreateGraphicShape(), AM_PRIMITIVE::DrawBasicShape(), CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText(), DrawHalfOpenCylinder(), AR_MATRIX::drawSegmentQcq(), GBR_TO_PCB_EXPORTER::export_segarc_copper_item(), EXPORTER_PCB_VRML::ExportVrmlFootprint(), fillArcPOLY(), CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment(), GERBER_PLOTTER::FlashPadChamferRoundRect(), GERBER_PLOTTER::FlashPadCustom(), PSLIKE_PLOTTER::FlashPadOval(), HPGL_PLOTTER::FlashPadOval(), PSLIKE_PLOTTER::FlashPadRect(), HPGL_PLOTTER::FlashPadRect(), DXF_PLOTTER::FlashPadRect(), PSLIKE_PLOTTER::FlashPadTrapez(), GERBER_PLOTTER::FlashPadTrapez(), HPGL_PLOTTER::FlashPadTrapez(), DXF_PLOTTER::FlashPadTrapez(), GERBER_PLOTTER::FlashRegularPolygon(), geom_transf(), GERBER_DRAW_ITEM::GetABPosition(), CN_ITEM::GetAnchor(), EDA_SHAPE::GetArcMid(), FP_SHAPE::GetArcMid0(), LIB_TEXT::GetBoundingBox(), SCH_FIELD::GetBoundingBox(), LIB_FIELD::GetBoundingBox(), LIB_PIN::GetBoundingBox(), SCH_TEXT::GetBoundingBox(), EDA_SHAPE::getBoundingBox(), SCH_LABEL::GetBoundingBox(), EDA_RECT::GetBoundingBoxRotated(), DS_DATA_ITEM_POLYGONS::GetCornerPosition(), CADSTAR_PCB_ARCHIVE_LOADER::getKiCadPad(), EDA_TEXT::GetLinePositions(), CADSTAR_SCH_ARCHIVE_LOADER::getLocationOfNetElement(), EDA_SHAPE::GetRectCorners(), ARRAY_CIRCULAR_OPTIONS::GetTransform(), GERBER_DRAW_ITEM::GetXYPosition(), GRArc(), GRCSegm(), ALTIUM_PCB::HelperParseDimensions6Center(), ALTIUM_PCB::HelperParseDimensions6Leader(), idf_export_footprint(), RENDER_3D_RAYTRACE::insertHole(), EDA_RECT::Intersects(), SCH_LEGACY_PLUGIN_CACHE::loadArc(), LEGACY_PLUGIN::loadPAD(), EAGLE_PLUGIN::loadPlain(), CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances(), SCH_EAGLE_PLUGIN::loadSymbolRectangle(), CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary(), FOOTPRINT::MoveAnchorPosition(), EAGLE_PLUGIN::packageCircle(), SCH_ALTIUM_PLUGIN::ParseArc(), ALTIUM_PCB::ParseComponentsBodies6Data(), GPCB_FPL_CACHE::parseFOOTPRINT(), PCB_PARSER::parseFOOTPRINT_unchecked(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), GERBER_PLOTTER::plotRoundRectAsRegion(), FABMASTER::processArc(), PCB_TARGET::Rotate(), SCH_JUNCTION::Rotate(), SCH_NO_CONNECT::Rotate(), PCB_TRACK::Rotate(), PCB_TEXT::Rotate(), LIB_TEXT::Rotate(), SCH_BUS_ENTRY_BASE::Rotate(), FP_TEXT::Rotate(), SCH_BITMAP::Rotate(), LIB_FIELD::Rotate(), SCH_FIELD::Rotate(), SCH_SHEET_PIN::Rotate(), SCH_LINE::Rotate(), SCH_TEXT::Rotate(), LIB_PIN::Rotate(), PCB_DIMENSION_BASE::Rotate(), FOOTPRINT::Rotate(), PCB_ARC::Rotate(), EDA_SHAPE::rotate(), SCH_SHEET::Rotate(), SCH_GLOBALLABEL::Rotate(), ZONE::Rotate(), SCH_SYMBOL::Rotate(), PAD::Rotate(), SCH_GLOBALLABEL::Rotate90(), SCH_LINE::RotateEnd(), RotatePoint(), SCH_LINE::RotateStart(), EDA_SHAPE::SetArcAngleAndEnd(), FP_SHAPE::SetArcAngleAndEnd0(), DS_DATA_ITEM_POLYGONS::SetBoundingBox(), FP_SHAPE::SetDrawCoord(), FP_TEXT::SetDrawCoord(), PAD::SetDrawCoord(), FP_SHAPE::SetLocalCoord(), FP_TEXT::SetLocalCoord(), PAD::SetLocalCoord(), SHAPE_ARC::SHAPE_ARC(), PAD::ShapePos(), PLOTTER::sketchOval(), PNS_KICAD_IFACE_BASE::syncPad(), FP_TEXT::TextHitTest(), EDA_TEXT::TextHitTest(), AR_MATRIX::TraceFilledRectangle(), DIALOG_PAD_PROPERTIES::TransferDataFromWindow(), EAGLE_PLUGIN::transferPad(), BOARD_ADAPTER::transformArcToSegments(), EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon(), TransformCircleToPolygon(), TransformOvalToPolygon(), EDA_SHAPE::TransformShapeWithClearanceToPolygon(), PAD::TransformShapeWithClearanceToPolygon(), PCB_POINT_EDITOR::updateItem(), and GERBER_PLOTTER::writeApertureList().
void RotatePoint | ( | int * | pX, |
int * | pY, | ||
int | cx, | ||
int | cy, | ||
double | angle | ||
) |
Definition at line 269 of file trigo.cpp.
References PNS::angle(), and RotatePoint().
void RotatePoint | ( | wxPoint * | point, |
const wxPoint & | centre, | ||
double | angle | ||
) |
Definition at line 283 of file trigo.cpp.
References PNS::angle(), and RotatePoint().
Definition at line 295 of file trigo.cpp.
References PNS::angle(), RotatePoint(), VECTOR2< T >::x, and VECTOR2< T >::y.
void RotatePoint | ( | double * | pX, |
double * | pY, | ||
double | cx, | ||
double | cy, | ||
double | angle | ||
) |
Definition at line 307 of file trigo.cpp.
References PNS::angle(), and RotatePoint().
void RotatePoint | ( | double * | pX, |
double * | pY, | ||
double | angle | ||
) |
Definition at line 321 of file trigo.cpp.
References PNS::angle(), DECIDEG2RAD(), and NORMALIZE_ANGLE_POS().
bool SegmentIntersectsSegment | ( | const wxPoint & | a_p1_l1, |
const wxPoint & | a_p2_l1, | ||
const wxPoint & | a_p1_l2, | ||
const wxPoint & | a_p2_l2, | ||
wxPoint * | aIntersectionPoint = nullptr |
||
) |
Test if two lines intersect.
a_p1_l1 | The first point of the first line. |
a_p2_l1 | The second point of the first line. |
a_p1_l2 | The first point of the second line. |
a_p2_l2 | The second point of the second line. |
aIntersectionPoint | is filled with the intersection point if it exists |
Definition at line 61 of file trigo.cpp.
References KiROUND().
Referenced by EDA_RECT::Intersects().
bool TestSegmentHit | ( | const wxPoint & | aRefPoint, |
const wxPoint & | aStart, | ||
const wxPoint & | aEnd, | ||
int | aDist | ||
) |
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
aRefPoint | = reference point to test |
aStart | is the first end-point of the line segment |
aEnd | is the second end-point of the line segment |
aDist | = maximum distance for hit |
Definition at line 129 of file trigo.cpp.
References delta, SEG::Square(), and SEG::SquaredDistance().
Referenced by SCH_EAGLE_PLUGIN::addBusEntries(), EE_GRID_HELPER::computeAnchors(), DRAWING_TOOL::DrawVia(), SCH_BUS_ENTRY_BASE::HitTest(), DS_DRAW_ITEM_LINE::HitTest(), PCB_TRACK::HitTest(), GERBER_DRAW_ITEM::HitTest(), DS_DRAW_ITEM_RECT::HitTest(), SCH_LINE::HitTest(), EDA_SHAPE::hitTest(), SCH_EAGLE_PLUGIN::moveLabels(), and SCH_TEXT::UpdateDanglingState().