QCAD
Open Source 2D CAD
RTriangle Class Reference

Low-level mathematical representation of a triangle. More...

#include <RTriangle.h>

Inheritance diagram for RTriangle:
RShape RExplodable

Public Member Functions

virtual RTriangleclone () const
 
virtual bool flipHorizontal ()
 
virtual bool flipVertical ()
 
double getArea () const
 
virtual RBox getBoundingBox () const
 
virtual QList< RVectorgetCenterPoints () const
 
RVector getCorner (int i) const
 
double getD () const
 
virtual double getDistanceTo (const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const
 
virtual QList< RVectorgetEndPoints () const
 
virtual QList< QSharedPointer< RShape > > getExploded (int segments=RDEFAULT_MIN1) const
 
virtual double getLength () const
 
virtual QList< RVectorgetMiddlePoints () const
 
virtual RVector getNormal () const
 
virtual QList< RVectorgetPointCloud (double segmentLength) const
 
virtual QList< RVectorgetPointsWithDistanceToEnd (double distance, int from=RS::FromAny) const
 
virtual RShape::Type getShapeType () const
 
QSharedPointer< RShapegetTransformed (const QTransform &transform) const
 
virtual QList< RVectorgetVectorProperties () const
 
virtual RVector getVectorTo (const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const
 
bool isPointInQuadrant (const RVector &p) const
 
bool isPointInTriangle (const RVector &p, bool treatAsQuadrant=false) const
 
virtual bool mirror (const RLine &axis)
 
virtual bool move (const RVector &offset)
 
virtual bool rotate (double rotation, const RVector &center=RDEFAULT_RVECTOR)
 
 RTriangle ()
 Copyright (c) 2011-2018 by Andrew Mustun. More...
 
 RTriangle (const RVector &p1, const RVector &p2, const RVector &p3)
 Creates a triangle with the given corners. More...
 
virtual bool scale (const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
 
void setCorner (int i, const RVector &p)
 
virtual void setZ (double z)
 
virtual ~RTriangle ()
 
- Public Member Functions inherited from RShape
void dump () const
 
virtual bool equals (const RShape &other, double tolerance=RS::PointTolerance) const
 
virtual QList< RVectorfilterOnShape (const QList< RVector > &pointList, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
 
virtual double getAngleAt (double distance, RS::From from=RS::FromStart) const
 
virtual double getAngleAtPercent (double p) const
 
virtual double getAngleAtPoint (const RVector &pos) const
 
virtual QList< RVectorgetArcReferencePoints () const
 
virtual QList< bool > getBoolProperties () const
 
virtual RVector getClosestPointOnShape (const RVector &p, bool limited=true, double strictRange=RMAXDOUBLE) const
 
virtual double getDirection1 () const
 
virtual double getDirection2 () const
 
virtual double getDistanceFromStart (const RVector &p) const
 
virtual QList< double > getDistancesFromStart (const RVector &p) const
 
virtual QList< double > getDoubleProperties () const
 
virtual RVector getEndPoint () const
 
QList< RVectorgetIntersectionPoints (const RShape &other, bool limited=true, bool same=false, bool force=false) const
 
virtual QList< int > getIntProperties () const
 
virtual double getMaxDistanceTo (const QList< RVector > &points, bool limited=true, double strictRange=RMAXDOUBLE) const
 
virtual RVector getMiddlePoint () const
 
virtual QList< QSharedPointer< RShape > > getOffsetShapes (double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
 
virtual RVector getPointAtPercent (double p) const
 
virtual RVector getPointOnShape () const
 
virtual RVector getPointWithDistanceToEnd (double distance) const
 
virtual RVector getPointWithDistanceToStart (double distance) const
 
virtual QList< RVectorgetSelfIntersectionPoints () const
 
virtual RS::Side getSideOfPoint (const RVector &point) const
 
virtual RVector getStartPoint () const
 
virtual RS::Ending getTrimEnd (const RVector &trimPoint, const RVector &clickPoint)
 
virtual RVector getVectorFromEndpointTo (const RVector &point) const
 
virtual bool intersectsWith (const RShape &other, bool limited=true) const
 
virtual bool isDirected () const
 
virtual bool isInterpolated () const
 Reimplement and return true if this shape relies on interpolation for geometrical operations such as finding intersection points. More...
 
virtual bool isOnShape (const RVector &point, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
 
virtual bool reverse ()
 
 RShape ()
 
virtual bool scale (double scaleFactor, const RVector &center=RVector())
 
virtual QList< QSharedPointer< RShape > > splitAt (const QList< RVector > &points) const
 
virtual bool stretch (const RBox &area, const RVector &offset)
 
virtual bool stretch (const RPolyline &area, const RVector &offset)
 
virtual void to2D ()
 Flattens this shape to the X/Y plane. More...
 
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)
 
virtual ~RShape ()
 
- Public Member Functions inherited from RExplodable
virtual ~RExplodable ()
 

Static Public Member Functions

static RTriangle createArrow (const RVector &position, double direction, double size)
 
- Static Public Member Functions inherited from RShape
static const RExplodablecastToExplodable (const RShape *shape)
 
static QSharedPointer< RShapeellipseToArcCircleEllipse (const REllipse &ellipse)
 
static int getErrorCode ()
 
static QList< RVectorgetIntersectionPoints (const RShape &shape1, const RShape &shape2, bool limited=true, bool same=false, bool force=false)
 
static QList< RVectorgetIntersectionPointsAA (const RArc &arc1, const RArc &arc2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsAC (const RArc &arc1, const RCircle &circle2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsAE (const RArc &arc1, const REllipse &ellipse2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsAS (const RArc &arc1, const RSpline &spline2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsAT (const RArc &arc1, const RTriangle &triangle2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsAX (const RArc &arc1, const RExplodable &explodable2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsCC (const RCircle &circle1, const RCircle &circle2)
 
static QList< RVectorgetIntersectionPointsCE (const RCircle &circle1, const REllipse &ellipse2)
 
static QList< RVectorgetIntersectionPointsCS (const RCircle &circle1, const RSpline &spline2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsCX (const RCircle &circle1, const RExplodable &explodable2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsEE (const REllipse &ellipse1, const REllipse &ellipse2)
 Based on "Hughes and Chraibi (2011-2012), Calculating Ellipse Overlap Areas". More...
 
static QList< RVectorgetIntersectionPointsEE (const REllipse &ellipse1, const REllipse &ellipse2, bool limited)
 
static QList< RVectorgetIntersectionPointsES (const REllipse &ellipse1, const RSpline &spline2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsEX (const REllipse &ellipse1, const RExplodable &explodable2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsLA (const RLine &line1, const RArc &arc2, bool limited1, bool limited2)
 
static QList< RVectorgetIntersectionPointsLA (const RLine &line1, const RArc &arc2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsLC (const RLine &line1, const RCircle &circle2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsLE (const RLine &line1, const REllipse &ellipse2, bool limited1, bool limited2)
 
static QList< RVectorgetIntersectionPointsLE (const RLine &line1, const REllipse &ellipse2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsLL (const RLine &line1, const RLine &line2, bool limited1, bool limited2)
 
static QList< RVectorgetIntersectionPointsLL (const RLine &line1, const RLine &line2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsLS (const RLine &line1, const RSpline &spline2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsLT (const RLine &line1, const RTriangle &triangle2, bool limited1, bool limited2)
 
static QList< RVectorgetIntersectionPointsLT (const RLine &line1, const RTriangle &triangle2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsLX (const RLine &line1, const RExplodable &explodable2, bool limited=true)
 
static QList< RVectorgetIntersectionPointsSS (const RSpline &spline1, const RSpline &spline2, bool limited=true, bool same=false)
 
static QList< RVectorgetIntersectionPointsSX (const RSpline &spline1, const RExplodable &explodable2, bool limited)
 
static QList< RVectorgetIntersectionPointsXX (const RExplodable &explodable1, const RExplodable &explodable2, bool limited=true, bool same=false)
 
static QList< QSharedPointer< RShape > > getOffsetArcs (const RShape &shape, double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
 
static QList< QSharedPointer< RShape > > getOffsetLines (const RShape &shape, double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
 
static QList< QSharedPointer< RShape > > getReversedShapeList (const QList< QSharedPointer< RShape > > &shapes)
 
static RShapeProxygetShapeProxy ()
 
static bool hasProxy ()
 
static bool isArcShape (const RShape &s)
 
static bool isCircleShape (const RShape &s)
 
static bool isEllipseShape (const RShape &s)
 
static bool isFullEllipseShape (const RShape &s)
 
static bool isLineShape (const RShape &s)
 
static bool isPointShape (const RShape &s)
 
static bool isPolylineShape (const RShape &s)
 
static bool isRayShape (const RShape &s)
 
static bool isSplineShape (const RShape &s)
 
static bool isTriangleShape (const RShape &s)
 
static bool isXLineShape (const RShape &s)
 
static bool order (QList< QList< QSharedPointer< RShape > > > &boundary)
 Orders the given list of loops into a list of closed loops in which all shapes are connected end to start point. More...
 
static QSharedPointer< RShaperayToLine (QSharedPointer< RShape > shape)
 
static QList< QSharedPointer< RShape > > roundAllCorners (const QList< QSharedPointer< RShape > > &shapes, double radius)
 Round every corner of the list of given (connected) shapes with the given radius. More...
 
static QList< QSharedPointer< RShape > > roundShapes (const QSharedPointer< RShape > shape1, const RVector &clickPos1, const QSharedPointer< RShape > shape2, const RVector &clickPos2, bool trim, bool samePolyline, double radius, const RVector &pos)
 Rounds the given shape1 against shape2. More...
 
static QSharedPointer< RShapescaleArc (const RShape &shape, const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
 
static void setShapeProxy (RShapeProxy *p)
 
static QSharedPointer< RShapetransformArc (const RShape &shape, RShapeTransformation &transformation)
 
static QList< QSharedPointer< RShape > > trim (const RShape &trimShape, const RVector &trimClickPos, const RShape &limitingShape, const RVector &limitingClickPos, bool trimBoth, bool samePolyline)
 Trims a shape to another or two shapes to each other. More...
 
static QSharedPointer< RShapexLineToRay (QSharedPointer< RShape > shape)
 

Public Attributes

RVector corner [3]
 

Protected Member Functions

virtual void print (QDebug dbg) const
 

Additional Inherited Members

- Public Types inherited from RShape
enum  Type {
  Unknown = -1, Point = 0, Line = 1, Arc = 2,
  Circle = 3, Ellipse = 4, Polyline = 5, Spline = 6,
  Triangle = 7, XLine = 8, Ray = 9
}
 
- Static Protected Attributes inherited from RShape
static int errorCode = 0
 

Detailed Description

Low-level mathematical representation of a triangle.

Scriptable:\nThis class is available in script environments.\n
Shared Pointer Support:\nObjects can be used in QSharedPointer.\n
Copyable:\nObjects are cleaned up automatically by the garbage collector of the script engine.\n
Stream Operator:\nObject has a stream operator to present itself as string, for example when using toString() in a script.\n

Constructor & Destructor Documentation

◆ RTriangle() [1/2]

RTriangle::RTriangle ( )

Copyright (c) 2011-2018 by Andrew Mustun.

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. Creates a triangle with invalid corner points.

◆ RTriangle() [2/2]

RTriangle::RTriangle ( const RVector p1,
const RVector p2,
const RVector p3 
)

Creates a triangle with the given corners.

◆ ~RTriangle()

RTriangle::~RTriangle ( )
virtual

Member Function Documentation

◆ clone()

virtual RTriangle* RTriangle::clone ( ) const
inlinevirtual

Implements RShape.

◆ createArrow()

RTriangle RTriangle::createArrow ( const RVector position,
double  direction,
double  size 
)
static

◆ flipHorizontal()

virtual bool RTriangle::flipHorizontal ( )
inlinevirtual

Reimplemented from RShape.

◆ flipVertical()

virtual bool RTriangle::flipVertical ( )
inlinevirtual

Reimplemented from RShape.

◆ getArea()

double RTriangle::getArea ( ) const

◆ getBoundingBox()

RBox RTriangle::getBoundingBox ( ) const
virtual
Returns
The bounding box of this shape.

Implements RShape.

◆ getCenterPoints()

QList< RVector > RTriangle::getCenterPoints ( ) const
virtual
Returns
The center point(s) of this shape.

Implements RShape.

◆ getCorner()

RVector RTriangle::getCorner ( int  i) const

◆ getD()

double RTriangle::getD ( ) const
Returns
'd' in the plane equation 'ax + by + cz = d'.

◆ getDistanceTo()

double RTriangle::getDistanceTo ( const RVector point,
bool  limited = true,
double  strictRange = RMAXDOUBLE 
) const
virtual
Returns
Shortest distance from this shape to the given point. Based on getVectorTo.

Reimplemented from RShape.

◆ getEndPoints()

QList< RVector > RTriangle::getEndPoints ( ) const
virtual
Returns
The end point(s) of this shape.

Implements RShape.

◆ getExploded()

QList< QSharedPointer< RShape > > RTriangle::getExploded ( int  segments = RDEFAULT_MIN1) const
virtual
Returns
List of RLines describing this triangle.

Implements RExplodable.

◆ getLength()

double RTriangle::getLength ( ) const
virtual
Returns
The total length of this shape if applicable or NaN if not.

Implements RShape.

◆ getMiddlePoints()

QList< RVector > RTriangle::getMiddlePoints ( ) const
virtual
Returns
The middle point(s) of this shape.

Implements RShape.

◆ getNormal()

RVector RTriangle::getNormal ( ) const
virtual
See also
http://en.wikipedia.org/wiki/Normal_vector
http://en.wikipedia.org/wiki/Cross_product#Definition
Returns
The normal vector of this triangle. The length of the normal vector equals double the area of the triangle.

◆ getPointCloud()

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

Implements RShape.

◆ getPointsWithDistanceToEnd()

QList< RVector > RTriangle::getPointsWithDistanceToEnd ( double  distance,
int  from = RS::FromAny 
) const
virtual
Returns
All points on this shape with the given distance to an endpoint.

Implements RShape.

◆ getShapeType()

virtual RShape::Type RTriangle::getShapeType ( ) const
inlinevirtual

Reimplemented from RShape.

◆ getTransformed()

QSharedPointer<RShape> RTriangle::getTransformed ( const QTransform &  transform) const
inlinevirtual

Implements RShape.

◆ getVectorProperties()

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

Reimplemented from RShape.

◆ getVectorTo()

RVector RTriangle::getVectorTo ( const RVector point,
bool  limited = true,
double  strictRange = RMAXDOUBLE 
) const
virtual
Returns
Shortest vector from this shape to the given point.
Parameters
pointthe given point
limitedIf false, the shape is treated as an unlimited shape that extends in a logical way. For example an unlimited line for a line, full circle for an arc or a plane for a triangle.

Implements RShape.

◆ isPointInQuadrant()

bool RTriangle::isPointInQuadrant ( const RVector p) const

◆ isPointInTriangle()

bool RTriangle::isPointInTriangle ( const RVector ip,
bool  treatAsQuadrant = false 
) const
Todo:
implement for all shapes
Returns
True if the given point is inside this triangle.
Parameters
ipthe point
treatAsQuadrantIf treatAsQuadrant is true, the triangle is treated as an open quadrant or segment with its center at the first corner. In this case, the point is inside, if it is on the plane that is limited by the two rays corner[0] -> corner[1] and corner[0] -> corner[2].

◆ mirror()

virtual bool RTriangle::mirror ( const RLine axis)
inlinevirtual

Implements RShape.

◆ move()

virtual bool RTriangle::move ( const RVector offset)
inlinevirtual

Implements RShape.

◆ print()

void RTriangle::print ( QDebug  dbg) const
protectedvirtual

Reimplemented from RShape.

◆ rotate()

virtual bool RTriangle::rotate ( double  rotation,
const RVector center = RDEFAULT_RVECTOR 
)
inlinevirtual

Implements RShape.

◆ scale()

virtual bool RTriangle::scale ( const RVector scaleFactors,
const RVector center = RDEFAULT_RVECTOR 
)
inlinevirtual

Implements RShape.

◆ setCorner()

void RTriangle::setCorner ( int  i,
const RVector p 
)

◆ setZ()

void RTriangle::setZ ( double  z)
virtual

Implements RShape.

Member Data Documentation

◆ corner

RVector RTriangle::corner[3]

The documentation for this class was generated from the following files: