Skip to content

REllipse

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

Low-level mathematical representation of an ellipse or ellipse 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.

REllipse()
Creates an ellipse shape with invalid.
REllipse(const RVector &center, const RVector &majorPoint, double ratio, double startParam, double endParam, bool reversed)
virtual ~REllipse()
double angleToParam(double a) const
RPolyline approximateWithArcs(int segments) const
QList< RSpline > approximateWithSplines() const
virtual QSharedPointer< RShape > clone() const
QSharedPointer< REllipse > cloneToEllipse() const
bool contains(const RVector &p) const
void correctMajorMinor()
Makes sure that the major axis of this ellipse is at least as long as its minor axis by switching the two axes if necessary.
double getAngle() const
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
virtual double getAngleAtPoint(const RVector &pos) const
double getAngleLength(bool allowForZeroLength=false) const
virtual QList< bool > getBoolProperties() const
virtual RBox getBoundingBox() const
QList< RVector > getBoxCorners()
RVector getCenter() const
virtual QList< RVector > getCenterPoints() const
virtual double getDirection1() const
virtual double getDirection2() const
virtual double getDistanceFromStart(const RVector &p) const
virtual QList< double > getDoubleProperties() const
double getEndAngle() const
double getEndParam() const
virtual RVector getEndPoint() const
virtual QList< RVector > getEndPoints() const
QList< RVector > getFoci() const
virtual double getLength() const
RVector getMajorPoint() const
double getMajorRadius() const
virtual RVector getMiddlePoint() const
virtual QList< RVector > getMiddlePoints() const
RVector getMinorPoint() const
double getMinorRadius() const
virtual QList< QSharedPointer< RShape > > getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
double getParamTo(const RVector &pos) const
RVector getPointAt(double param) const
virtual QList< RVector > getPointCloud(double segmentLength) const
virtual RVector getPointOnShape() const
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const
double getRadiusAt(double param) const
double getRatio() const
virtual RShape::Type getShapeType() const
virtual RS::Side getSideOfPoint(const RVector &point) const
double getSimpsonLength(double f1, double f2) const
double getStartAngle() const
double getStartParam() const
virtual RVector getStartPoint() const
double getSweep() const
RVector getTangentPoint(const RLine &line) 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
bool isCircular() const
virtual bool isDirected() const
bool isFullEllipse() const
bool isParamWithinArc(double a) const
bool isReversed() const
virtual bool isValid() const
virtual bool mirror(const RLine &axis)
virtual bool move(const RVector &offset)
void moveEndPoint(const RVector &pos, bool changeAngleOnly=false)
void moveStartPoint(const RVector &pos, bool changeAngleOnly=false)
virtual bool reverse()
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
void setAngle(double a)
Sets the rotation angle of this ellipse without changing the major radius.
void setCenter(const RVector &vector)
void setEndAngle(double a)
void setEndParam(double endParam)
void setMajorPoint(const RVector &vector)
Sets the major point relative to the center point.
void setMinorPoint(const RVector &p)
Sets the minor point relative to the center point.
void setRatio(double radius)
void setReversed(bool reversed)
void setStartAngle(double a)
void setStartParam(double startParam)
virtual void setZ(double z)
virtual QList< QSharedPointer< RShape > > splitAt(const QList< RVector > &points) const
bool switchMajorMinor()
Switches the major and the minor axis of this ellipse.
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
virtual bool trimEndPoint(double trimDist)
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
virtual bool trimStartPoint(double trimDist)
static REllipse createFrom4Points(const RVector &p1, const RVector &p2, const RVector &p3, const RVector &p4)
static REllipse createInscribed(const RVector &p1, const RVector &p2, const RVector &p3, const RVector &p4, const RVector &centerHint=RVector::invalid)
Produces an ellipse inscribed in the quadrilateral defined by the four given ordered vertices (RVector).
static REllipseProxy * getEllipseProxy()
static bool hasProxy()
static void setEllipseProxy(REllipseProxy *p)
RVector center
Getter function for this property: getCenter.
double endParam
Getter function for this property: getEndParam.
RVector majorPoint
Getter function for this property: getMajorPoint.
double ratio
Getter function for this property: getRatio.
bool reversed
Getter function for this property: isReversed.
double startParam
Getter function for this property: getStartParam.
virtual void print(QDebug dbg) const
static REllipseProxy * ellipseProxy

REllipse::REllipse()

Creates an ellipse shape with invalid.

REllipse::REllipse(const RVector &center, const RVector &majorPoint, double ratio, double startParam, double endParam, bool reversed)

virtual REllipse::~REllipse()

virtual

double REllipse::angleToParam(double a) const

const

RPolyline REllipse::approximateWithArcs(int segments) const

const

QList< RSpline > REllipse::approximateWithSplines() const

const

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

virtual inline const

Reimplemented from clone.

QSharedPointer< REllipse > REllipse::cloneToEllipse() const

inline const

bool REllipse::contains(const RVector &p) const

const

void REllipse::correctMajorMinor()

Makes sure that the major axis of this ellipse is at least as long as its minor axis by switching the two axes if necessary.

double REllipse::getAngle() const

const

Returns: The rotation angle of this ellipse.

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

virtual const

Returns: Angle on the entity at the given distance from the start point.

Reimplemented from getAngleAt.

virtual double REllipse::getAngleAtPoint(const RVector &pos) const

virtual const

Reimplemented from getAngleAtPoint.

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

const

Returns: Angle length in rad.

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

virtual const

Reimplemented from getBoolProperties.

virtual RBox REllipse::getBoundingBox() const

virtual const

Returns: The bounding box of this shape.

Reimplemented from getBoundingBox.

QList< RVector > REllipse::getBoxCorners()

RVector REllipse::getCenter() const

const

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

virtual const

Returns: The center point(s) of this shape.

Reimplemented from getCenterPoints.

virtual double REllipse::getDirection1() const

virtual const

Reimplemented from getDirection1.

virtual double REllipse::getDirection2() const

virtual const

Reimplemented from getDirection2.

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

virtual const

Returns: Arc length distance from the start point of this ellipse (arc) to the given point, measured along the ellipse in the direction of the shape.

Parameters:

  • p: Point (assumed to be on the shape).

Reimplemented from getDistanceFromStart.

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

virtual const

Reimplemented from getDoubleProperties.

double REllipse::getEndAngle() const

const

Returns: End angle: the angle from the ellipse arc center to the ellipse arc end point.

double REllipse::getEndParam() const

const

Returns: End parameter: the end angle of the circular arc resulting from transforming the ellipse into a circle.

virtual RVector REllipse::getEndPoint() const

virtual const

Reimplemented from getEndPoint.

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

virtual const

Returns: The end point(s) of this shape.

Reimplemented from getEndPoints.

QList< RVector > REllipse::getFoci() const

const

virtual double REllipse::getLength() const

virtual const

Returns: Approximation for ellipse arc length.

Reimplemented from getLength.

Reimplemented in getLength.

RVector REllipse::getMajorPoint() const

const

Returns: Major point relative to the center point.

double REllipse::getMajorRadius() const

const

Returns: The major radius of this ellipse.

virtual RVector REllipse::getMiddlePoint() const

virtual const

Reimplemented from getMiddlePoint.

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

virtual const

Returns: Middle point of the ellipse arc (at half its arc length). Empty for full ellipses or if no ellipse proxy is available.

Reimplemented from getMiddlePoints.

RVector REllipse::getMinorPoint() const

const

Returns: Minor point relative to the center point.

double REllipse::getMinorRadius() const

const

Returns: The minor radius of this ellipse.

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

virtual

Returns: Array of spline shapes representing the parallel curves to this ellipse shape.

Reimplemented from getOffsetShapes.

double REllipse::getParamTo(const RVector &pos) const

const

RVector REllipse::getPointAt(double param) const

const

Returns: Point on ellipse at given ellipse angle.

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

virtual const

Reimplemented from getPointCloud.

virtual RVector REllipse::getPointOnShape() const

virtual const

Reimplemented from getPointOnShape.

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

virtual const

Returns: Point(s) on the ellipse at arc length distance from the start and / or end, controlled by the from bitmask (RS::FromStart, RS::FromEnd, RS::FromAny). Empty if no ellipse proxy is available.

Reimplemented from getPointsWithDistanceToEnd.

double REllipse::getRadiusAt(double param) const

const

Returns: Radius of ellipse at given ellipse angle.

double REllipse::getRatio() const

const

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

virtual inline const

Reimplemented from getShapeType.

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

virtual const

Reimplemented from getSideOfPoint.

double REllipse::getSimpsonLength(double f1, double f2) const

const

Returns: Length of the ellipse segment from angle a1 to angle a2.

double REllipse::getStartAngle() const

const

Returns: Start angle: the angle from the ellipse arc center to the ellipse arc start point.

double REllipse::getStartParam() const

const

Returns: Start parameter: the start angle of the circular arc resulting from transforming the ellipse into a circle.

virtual RVector REllipse::getStartPoint() const

virtual const

Reimplemented from getStartPoint.

double REllipse::getSweep() const

const

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

RVector REllipse::getTangentPoint(const RLine &line) const

const

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

const

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

virtual const

Reimplemented from getTransformed.

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

virtual

Parameters:

  • trimPoint: Trim start point or end point to this coordinate.
  • clickPoint: Point that was clicked by user.

Reimplemented from getTrimEnd.

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

virtual const

Reimplemented from getVectorProperties.

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

virtual const

Returns: Vector from the closest point on this ellipse to the given point or an invalid vector if there is no such point.

Parameters:

  • limited: True to only consider the ellipse arc from start to end parameter, false to consider the full ellipse.

The closest point is found with a fixed point iteration which exploits the evolute of the ellipse and needs no trigonometric functions, followed by a Newton refinement of the parametric angle. Points in line with one of the two axes and degenerate ellipses are handled separately.

The iteration was contributed as a proof of concept by CVH in the QCAD forum thread “REllipse.getVectorTo(p) exceptions (FS#2564)”, based on the method of Carl Chatfield and a trigonometry free variant of it by Adrian Stephens: https://forum.qcad.org/t/rellipse-getvectorto-p-exceptions-fs-2564/9284 https://blog.chatfield.io/simple-method-for-distance-to-ellipse/ https://github.com/0xfaded/ellipse_demo/issues/1

Reimplemented from getVectorTo.

Reimplemented in getVectorTo.

bool REllipse::isAngleWithinArc(double a) const

inline const

bool REllipse::isCircular() const

const

Returns: True if minor radius and major radius are equal, i.e. ratio is 1.0.

virtual bool REllipse::isDirected() const

virtual inline const

Reimplemented from isDirected.

bool REllipse::isFullEllipse() const

const

bool REllipse::isParamWithinArc(double a) const

inline const

bool REllipse::isReversed() const

const

virtual bool REllipse::isValid() const

virtual const

Reimplemented from isValid.

Reimplemented in isValid.

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

virtual

Reimplemented from mirror.

Reimplemented in mirror.

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

virtual

Reimplemented from move.

Reimplemented in move.

void REllipse::moveEndPoint(const RVector &pos, bool changeAngleOnly=false)

void REllipse::moveStartPoint(const RVector &pos, bool changeAngleOnly=false)

virtual bool REllipse::reverse()

virtual

Reimplemented from reverse.

Reimplemented in reverse.

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

virtual

Reimplemented from rotate.

Reimplemented in rotate.

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

virtual

Reimplemented from scale.

Reimplemented in scale.

void REllipse::setAngle(double a)

Sets the rotation angle of this ellipse without changing the major radius.

void REllipse::setCenter(const RVector &vector)

void REllipse::setEndAngle(double a)

void REllipse::setEndParam(double endParam)

void REllipse::setMajorPoint(const RVector &vector)

Sets the major point relative to the center point.

void REllipse::setMinorPoint(const RVector &p)

Sets the minor point relative to the center point.

void REllipse::setRatio(double radius)

void REllipse::setReversed(bool reversed)

void REllipse::setStartAngle(double a)

void REllipse::setStartParam(double startParam)

virtual void REllipse::setZ(double z)

virtual

Reimplemented from setZ.

Reimplemented in setZ.

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

virtual const

Returns: Array of shapes which represent the given shape split up at the given points.

Parameters:

  • points: Array of RVector, assumed to be on shape.

Reimplemented from splitAt.

bool REllipse::switchMajorMinor()

Switches the major and the minor axis of this ellipse.

The ellipse remains unchanged, only its representation changes: the ratio is inverted and the parameters are adjusted accordingly.

Returns: False for a ratio of zero or a negative (invalid) ratio.

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

virtual

Parameters:

  • trimPoint: Trim start point or end point to this coordinate.
  • clickPoint: Point that was clicked by user.
  • extend: True if the shape is to be extended. Used for polylines to determine that the last segment has to be trimmed even if another segment was clicked.

Reimplemented from trimEndPoint.

virtual bool REllipse::trimEndPoint(double trimDist)

virtual inline

Reimplemented from trimEndPoint.

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

virtual

Parameters:

  • trimPoint: Trim start point or end point to this coordinate.
  • clickPoint: Point that was clicked by user.
  • extend: True if the shape is to be extended. Used for polylines to determine that the first segment has to be trimmed even if another segment was clicked.

Reimplemented from trimStartPoint.

virtual bool REllipse::trimStartPoint(double trimDist)

virtual inline

Reimplemented from trimStartPoint.

static REllipse REllipse::createFrom4Points(const RVector &p1, const RVector &p2, const RVector &p3, const RVector &p4)

static

static REllipse REllipse::createInscribed(const RVector &p1, const RVector &p2, const RVector &p3, const RVector &p4, const RVector &centerHint=RVector::invalid)

static

Produces an ellipse inscribed in the quadrilateral defined by the four given ordered vertices (RVector).

Parameters:

  • centerHint: Hint for the position of the center (e.g. mouse cursor for interactive tools) or invalid for maximum area solution.

Returns: Inscribed ellipse or invalid ellipse.

static REllipseProxy * REllipse::getEllipseProxy()

static inline

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

static bool REllipse::hasProxy()

static inline

static void REllipse::setEllipseProxy(REllipseProxy *p)

static inline

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

RVector REllipse::center

Getter function for this property: getCenter.

Setter function for this property: setCenter

double REllipse::endParam

Getter function for this property: getEndParam.

Setter function for this property: setEndParam

RVector REllipse::majorPoint

Getter function for this property: getMajorPoint.

Setter function for this property: setMajorPoint

double REllipse::ratio

Getter function for this property: getRatio.

Setter function for this property: setRatio

bool REllipse::reversed

Getter function for this property: isReversed.

Setter function for this property: setReversed

double REllipse::startParam

Getter function for this property: getStartParam.

Setter function for this property: setStartParam

virtual void REllipse::print(QDebug dbg) const

virtual const protected

Reimplemented from print.

static REllipseProxy * REllipse::ellipseProxy = 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.