Skip to content

RArc

Class in Math Module
Header: #include <src/core/math/RArc.h>
Inherits: RShape
Inherited by: RArcData

Low-level mathematical representation of an arc.

Scriptable: This class is available in script environments.

Shared Pointer Support: Objects can be used in QSharedPointer.

Copyable: Objects are cleaned up automatically by the garbage collector of the script engine.

Stream Operator: Object has a stream operator to present itself as string, for example when using toString() in a script.

RArc()
Creates an arc shape with an invalid center.
RArc(const RVector &center, double radius, double startAngle, double endAngle, bool reversed=false)
Creates an arc from a center point, radius, start/end angles (in rad) and direction.
RArc(double cx, double cy, double radius, double startAngle, double endAngle, bool reversed=false)
Creates an arc from center coordinates, radius, start/end angles (in rad) and direction.
RPolyline approximateWithLines(double segmentLength, double angle=0.0) const
RPolyline approximateWithLinesTan(double segmentLength, double angle=0.0) const
virtual QSharedPointer< RShape > clone() const
QSharedPointer< RArc > cloneToArc() const
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
double getAngleLength(bool allowForZeroLength=false) const
virtual QList< RVector > getArcReferencePoints() const
double getArea() const
virtual QList< bool > getBoolProperties() const
virtual RBox getBoundingBox() const
double getBulge() const
RVector getCenter() const
virtual QList< RVector > getCenterPoints() const
double getChordArea() const
double getDiameter() const
virtual double getDirection1() const
virtual double getDirection2() const
virtual double getDistanceFromStart(const RVector &p) const
virtual QList< double > getDoubleProperties() const
double getEndAngle() const
virtual RVector getEndPoint() const
virtual QList< RVector > getEndPoints() const
virtual double getLength() const
virtual RVector getMiddlePoint() const
virtual QList< RVector > getMiddlePoints() const
virtual QList< QSharedPointer< RShape > > getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
RVector getPointAtAngle(double a) const
virtual QList< RVector > getPointCloud(double segmentLength) const
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const
double getRadius() const
virtual RShape::Type getShapeType() const
virtual RS::Side getSideOfPoint(const RVector &point) const
double getStartAngle() const
virtual RVector getStartPoint() const
double getSweep() const
QList< RLine > getTangents(const RVector &point) const
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)
virtual QList< RVector > getVectorProperties() const
virtual RVector getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const
bool isAngleWithinArc(double a) const
virtual bool isDirected() const
bool isFullCircle(double tolerance=RS::AngleTolerance) const
bool isReversed() const
virtual bool isValid() const
virtual bool mirror(const RLine &axis)
Mirrors the arc about axis.
virtual bool move(const RVector &offset)
Moves the arc by offset.
void moveEndPoint(const RVector &pos, bool keepRadius=true)
Moves the end point of the arc, optionally keeping the radius.
void moveMiddlePoint(const RVector &pos)
Moves the midpoint of the arc to pos by reconstructing from current start/end and the new middle point.
void moveStartPoint(const RVector &pos, bool keepRadius=true)
Moves the start point of the arc, optionally keeping the radius.
virtual bool reverse()
Reverses the arc direction by swapping start/end angles and toggling the reversed flag.
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Rotates the arc around c by rotation radians.
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Scales the arc by scaleFactors relative to c.
void setArea(double a)
Sets the arc sweep angle by adjusting the end angle to match the given sector area.
void setCenter(const RVector &vector)
Sets the center point of the arc.
void setDiameter(double d)
Sets the radius from a diameter value.
void setEndAngle(double endAngle)
Sets the end angle, normalizing it to [0, 2π).
void setLength(double l)
Sets the arc length by adjusting the end angle (keeping start angle and radius).
void setRadius(double radius)
Sets the radius of the arc.
void setReversed(bool reversed)
Sets the arc direction: true = clockwise, false = counter-clockwise.
void setStartAngle(double startAngle)
Sets the start angle, normalizing it to [0, 2π).
void setSweep(double s)
Sets the sweep angle (end = start + s); sets reversed if s < 0.
virtual void setZ(double z)
Sets the Z coordinate of the center point.
virtual QList< QSharedPointer< RShape > > splitAt(const QList< RVector > &points) const
Splits this arc at the given points (sorted by angle from start).
QList< RArc > splitAtQuadrantLines() const
virtual bool stretch(const RPolyline &area, const RVector &offset)
Stretches the arc by moving endpoint(s) inside area by offset.
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Trims the end of the arc to the angle corresponding to trimPoint.
virtual bool trimEndPoint(double trimDist)
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Trims the start of the arc to the angle corresponding to trimPoint.
virtual bool trimStartPoint(double trimDist)
static QList< RArc > createBiarc(const RVector &startPoint, double startDirection, const RVector &endPoint, double endDirection, bool secondTry=false)
Creates a biarc (pair of two arcs) with the given conditions.
static RArc createFrom2PBulge(const RVector &startPoint, const RVector &endPoint, double bulge)
Creates an arc from its startpoint, endpoint and bulge (= tan(angle/4)).
static RArc createFrom3Points(const RVector &startPoint, const RVector &point, const RVector &endPoint)
Creates an arc from 3 points.
static RArc createTangential(const RVector &startPoint, const RVector &pos, double direction, double radius=0.0, double sweep=0.0)
Creates an arc tangent to a given direction at startPoint, passing near pos.
static RArcProxy * getArcProxy()
static bool hasProxy()
static void setArcProxy(RArcProxy *p)
RVector center
Getter function for this property: getCenter.
double endAngle
Getter function for this property: getEndAngle.
double radius
Getter function for this property: getRadius.
bool reversed
Getter function for this property: isReversed.
double startAngle
Getter function for this property: getStartAngle.
virtual void print(QDebug dbg) const
Prints arc properties to dbg for debugging.
static RArcProxy * arcProxy

RArc::RArc()

Creates an arc shape with an invalid center.

RArc::RArc(const RVector &center, double radius, double startAngle, double endAngle, bool reversed=false)

Creates an arc from a center point, radius, start/end angles (in rad) and direction.

RArc::RArc(double cx, double cy, double radius, double startAngle, double endAngle, bool reversed=false)

Creates an arc from center coordinates, radius, start/end angles (in rad) and direction.

RPolyline RArc::approximateWithLines(double segmentLength, double angle=0.0) const

const

Returns: Polyline approximation of arc with line segments of given length or (if length is 0) given angle. Polyline is on the inside of the arc.

RPolyline RArc::approximateWithLinesTan(double segmentLength, double angle=0.0) const

const

Returns: Polyline approximation of arc with line segments of given length or (if length is 0) given angle. Polyline is on the outside of the arc.

virtual QSharedPointer< RShape > RArc::clone() const

virtual inline const

Reimplemented from clone.

QSharedPointer< RArc > RArc::cloneToArc() const

inline const

virtual double RArc::getAngleAt(double distance, RS::From from=RS::FromStart) const

virtual const

Returns: Tangent direction angle at the point on the arc at the given arc-length distance from the start or end. Returns RNANDOUBLE if no such point exists.

Reimplemented from getAngleAt.

double RArc::getAngleLength(bool allowForZeroLength=false) const

const

Returns: Angle length in rad.

Parameters:

  • allowForZeroLength: Allow for zero length result if start and end angle are the same. Otherwise 2*PI will be returned for such an arc, assuming it is a full circle.

virtual QList< RVector > RArc::getArcReferencePoints() const

virtual const

Returns: The quadrant extremes (0°, 90°, 180°, 270° points on the circle) that lie within the arc. Used as snappable reference points.

Reimplemented from getArcReferencePoints.

double RArc::getArea() const

const

Returns: Area of the circular sector (pie slice) defined by this arc.

virtual QList< bool > RArc::getBoolProperties() const

virtual const

Returns: List of boolean properties: reversed.

Reimplemented from getBoolProperties.

virtual RBox RArc::getBoundingBox() const

virtual const

Returns: Axis-aligned bounding box of this arc. Checks which of the four quadrant extremes (0°, 90°, 180°, 270°) lie within the arc and expands the box accordingly.

Reimplemented from getBoundingBox.

double RArc::getBulge() const

const

Returns: Bulge value (tan(sweep/4)), negative for clockwise arcs. Used in DXF/DWG polyline vertex encoding.

RVector RArc::getCenter() const

const

Returns: Center point of the arc.

virtual QList< RVector > RArc::getCenterPoints() const

virtual const

Returns: List containing the center point of the arc.

Reimplemented from getCenterPoints.

double RArc::getChordArea() const

const

Returns: Area of the circular segment bounded by the arc and its chord (the region between the arc and the straight line connecting start and end point).

Derivation: segment = sector − isosceles_triangle(center, p1, p2) sector area = r²θ/2 triangle area = r²sin(θ)/2 → segment = r²(θ − sin θ)/2

This formula is correct for all arc angles (minor, major, full circle).

double RArc::getDiameter() const

const

Returns: Diameter (2 * radius).

virtual double RArc::getDirection1() const

virtual const

Returns: Tangent direction at the start point (in rad): perpendicular to the radius, pointing in the direction of travel.

Reimplemented from getDirection1.

Reimplemented in getDirection1.

virtual double RArc::getDirection2() const

virtual const

Returns: Tangent direction at the end point (in rad), pointing away from the arc.

Reimplemented from getDirection2.

Reimplemented in getDirection2.

virtual double RArc::getDistanceFromStart(const RVector &p) const

virtual const

Returns: Arc-length distance from the start point to the projection of p onto the arc’s circle (i.e. the point at the angle from center to p).

Reimplemented from getDistanceFromStart.

virtual QList< double > RArc::getDoubleProperties() const

virtual const

Returns: List of scalar properties: radius, startAngle, endAngle.

Reimplemented from getDoubleProperties.

double RArc::getEndAngle() const

const

Returns: End angle in radians (normalized to [0, 2π)).

virtual RVector RArc::getEndPoint() const

virtual const

Returns: End point of the arc.

Reimplemented from getEndPoint.

virtual QList< RVector > RArc::getEndPoints() const

virtual const

Returns: List containing the start and end points of the arc.

Reimplemented from getEndPoints.

virtual double RArc::getLength() const

virtual const

Returns: Arc length (angle length * radius).

Reimplemented from getLength.

Reimplemented in getLength.

virtual RVector RArc::getMiddlePoint() const

virtual const

Returns: Point at the midpoint of the arc (halfway along the sweep).

Reimplemented from getMiddlePoint.

virtual QList< RVector > RArc::getMiddlePoints() const

virtual const

Returns: List containing the midpoint of the arc.

Reimplemented from getMiddlePoints.

virtual QList< QSharedPointer< RShape > > RArc::getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)

virtual inline

Returns: Parallels to this shape.

Parameters:

  • distance: Distance of first parallel or concentric arc or circle.
  • number: Number of offset shapes to generate.
  • side: Side, should be RS.LeftHand or RS.RightHand or RS.BothSides.
  • sidePosition: Position indicating what side of the shape the parallels should be.

Reimplemented from getOffsetShapes.

RVector RArc::getPointAtAngle(double a) const

const

Returns: Point on the arc at the given angle a (in radians).

virtual QList< RVector > RArc::getPointCloud(double segmentLength) const

virtual const

Returns: Dense set of points sampling the arc. Combines vertices from both the inscribed and circumscribed polyline approximations.

Reimplemented from getPointCloud.

virtual QList< RVector > RArc::getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const

virtual const

Returns: Point(s) on the arc at arc-length distance from the start and/or end, controlled by the from bitmask (RS::FromStart, RS::FromEnd, RS::FromAny).

Reimplemented from getPointsWithDistanceToEnd.

double RArc::getRadius() const

const

Returns: Radius of the arc.

virtual RShape::Type RArc::getShapeType() const

virtual inline const

Reimplemented from getShapeType.

virtual RS::Side RArc::getSideOfPoint(const RVector &point) const

virtual const

Returns: Which side of the arc the given point is on. A point inside the circle is on the left for CCW arcs, right for CW arcs.

Reimplemented from getSideOfPoint.

double RArc::getStartAngle() const

const

Returns: Start angle in radians (normalized to [0, 2π)).

virtual RVector RArc::getStartPoint() const

virtual const

Returns: Start point of the arc.

Reimplemented from getStartPoint.

double RArc::getSweep() const

const

Returns: Arc sweep in rad. The sweep is the angle covered by this arc. Positive for ccw, negative for cw.

QList< RLine > RArc::getTangents(const RVector &point) const

const

Returns: The tangent lines from the external point to this arc’s circle. Delegates to RCircle::getTangents.

virtual QSharedPointer< RShape > RArc::getTransformed(const QTransform &transform) const

virtual const

Reimplemented from getTransformed.

virtual RS::Ending RArc::getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)

virtual

Returns: Which end of the arc is closer to clickPoint relative to trimPoint. Used to decide which end to trim when the user clicks near a trim point.

Reimplemented from getTrimEnd.

Reimplemented in getTrimEnd.

virtual QList< RVector > RArc::getVectorProperties() const

virtual const

Returns: List containing the center point (used for property-based transformations).

Reimplemented from getVectorProperties.

virtual RVector RArc::getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const

virtual const

Returns: Vector from the nearest point on the arc to point, or RVector::invalid if limited is true and the projection falls outside the arc span. Note: strictRange is not implemented.

Reimplemented from getVectorTo.

Reimplemented in getVectorTo.

bool RArc::isAngleWithinArc(double a) const

inline const

virtual bool RArc::isDirected() const

virtual inline const

Reimplemented from isDirected.

bool RArc::isFullCircle(double tolerance=RS::AngleTolerance) const

const

Returns: True if the start and end angles are equal within tolerance, indicating that this arc spans a full circle.

bool RArc::isReversed() const

const

Returns: True if the arc is clockwise (reversed).

virtual bool RArc::isValid() const

virtual const

Returns: True if the center is valid and the radius is positive.

Reimplemented from isValid.

Reimplemented in isValid.

virtual bool RArc::mirror(const RLine &axis)

virtual

Mirrors the arc about axis.

Reverses the arc direction and reflects the start/end angles. Full circles only need their center mirrored.

Reimplemented from mirror.

Reimplemented in mirror.

virtual bool RArc::move(const RVector &offset)

virtual

Moves the arc by offset.

Returns false if the offset is invalid or negligibly small. Uses squared magnitude to avoid a sqrt call; tolerance is squared accordingly.

Reimplemented from move.

Reimplemented in move.

void RArc::moveEndPoint(const RVector &pos, bool keepRadius=true)

Moves the end point of the arc, optionally keeping the radius.

If keepRadius is true and the arc is not a full circle, the arc is reconstructed from the current start point and the new end point with the same bulge. If keepRadius is false, the arc is reconstructed from the current start point, the current middle point and the new end point.

void RArc::moveMiddlePoint(const RVector &pos)

Moves the midpoint of the arc to pos by reconstructing from current start/end and the new middle point.

void RArc::moveStartPoint(const RVector &pos, bool keepRadius=true)

Moves the start point of the arc, optionally keeping the radius.

If keepRadius is true and the arc is not a full circle, the arc is reconstructed from the new start point and the current end point with the same bulge. If keepRadius is false, the arc is reconstructed from the new start point, the current middle point and end point.

virtual bool RArc::reverse()

virtual

Reverses the arc direction by swapping start/end angles and toggling the reversed flag.

Reimplemented from reverse.

Reimplemented in reverse.

virtual bool RArc::rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)

virtual

Rotates the arc around c by rotation radians.

Skips angle update for full circles.

Reimplemented from rotate.

Reimplemented in rotate.

virtual bool RArc::scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)

virtual

Scales the arc by scaleFactors relative to c.

Negative scale factors are decomposed into a mirror plus a positive scale. Only uniform XY scaling is supported for the radius (scaleFactors.x is used).

Reimplemented from scale.

Reimplemented in scale.

void RArc::setArea(double a)

Sets the arc sweep angle by adjusting the end angle to match the given sector area.

void RArc::setCenter(const RVector &vector)

Sets the center point of the arc.

void RArc::setDiameter(double d)

Sets the radius from a diameter value.

void RArc::setEndAngle(double endAngle)

Sets the end angle, normalizing it to [0, 2π).

void RArc::setLength(double l)

Sets the arc length by adjusting the end angle (keeping start angle and radius).

void RArc::setRadius(double radius)

Sets the radius of the arc.

void RArc::setReversed(bool reversed)

Sets the arc direction: true = clockwise, false = counter-clockwise.

void RArc::setStartAngle(double startAngle)

Sets the start angle, normalizing it to [0, 2π).

void RArc::setSweep(double s)

Sets the sweep angle (end = start + s); sets reversed if s < 0.

virtual void RArc::setZ(double z)

virtual

Sets the Z coordinate of the center point.

Reimplemented from setZ.

Reimplemented in setZ.

virtual QList< QSharedPointer< RShape > > RArc::splitAt(const QList< RVector > &points) const

virtual const

Splits this arc at the given points (sorted by angle from start).

Reversed arcs are temporarily flipped, split, then the result list is reversed.

Reimplemented from splitAt.

QList< RArc > RArc::splitAtQuadrantLines() const

const

Returns: This arc split at the quadrant angles (0°, 90°, 180°, 270°) that lie within the arc span. Useful for bounding-box calculations.

virtual bool RArc::stretch(const RPolyline &area, const RVector &offset)

virtual

Stretches the arc by moving endpoint(s) inside area by offset.

If both endpoints are inside, the whole arc is moved.

Reimplemented from stretch.

Reimplemented in stretch.

virtual bool RArc::trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)

virtual

Trims the end of the arc to the angle corresponding to trimPoint.

Reimplemented from trimEndPoint.

Reimplemented in trimEndPoint.

virtual bool RArc::trimEndPoint(double trimDist)

virtual inline

Reimplemented from trimEndPoint.

virtual bool RArc::trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)

virtual

Trims the start of the arc to the angle corresponding to trimPoint.

Reimplemented from trimStartPoint.

Reimplemented in trimStartPoint.

virtual bool RArc::trimStartPoint(double trimDist)

virtual inline

Reimplemented from trimStartPoint.

static QList< RArc > RArc::createBiarc(const RVector &startPoint, double startDirection, const RVector &endPoint, double endDirection, bool secondTry=false)

static

Creates a biarc (pair of two arcs) with the given conditions.

static RArc RArc::createFrom2PBulge(const RVector &startPoint, const RVector &endPoint, double bulge)

static

Creates an arc from its startpoint, endpoint and bulge (= tan(angle/4)).

static RArc RArc::createFrom3Points(const RVector &startPoint, const RVector &point, const RVector &endPoint)

static

Creates an arc from 3 points.

static RArc RArc::createTangential(const RVector &startPoint, const RVector &pos, double direction, double radius=0.0, double sweep=0.0)

static

Creates an arc tangent to a given direction at startPoint, passing near pos.

Delegates to the arc proxy if available.

static RArcProxy * RArc::getArcProxy()

static inline

Non-Scriptable: This function is not available in script environments.

static bool RArc::hasProxy()

static inline

static void RArc::setArcProxy(RArcProxy *p)

static inline

Non-Scriptable: This function is not available in script environments.

RVector RArc::center

Getter function for this property: getCenter.

Setter function for this property: setCenter

double RArc::endAngle

Getter function for this property: getEndAngle.

Setter function for this property: setEndAngle

double RArc::radius

Getter function for this property: getRadius.

Setter function for this property: setRadius

bool RArc::reversed

Getter function for this property: isReversed.

Setter function for this property: setReversed

double RArc::startAngle

Getter function for this property: getStartAngle.

Setter function for this property: setStartAngle

virtual void RArc::print(QDebug dbg) const

virtual const protected

Prints arc properties to dbg for debugging.

Reimplemented from print.

static RArcProxy * RArc::arcProxy = NULL

static private

All rights reserved.

This file is part of the QCAD project.

QCAD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

QCAD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with QCAD.