/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file Triangle.h14/// @author Pablo Alvarez Lopez15/// @date Jan 202516///17// A simple triangle defined in 3D18/****************************************************************************/19#pragma once20#include <config.h>2122#include <vector>2324#include "PositionVector.h"25#include "Boundary.h"2627// ===========================================================================28// class definitions29// ===========================================================================30/**31* @class Triangle32* @brief A simple triangle defined in 3D33*/34class Triangle {3536public:37/// @brief invalid triangle38static const Triangle INVALID;3940/// @brief default constructor41Triangle();4243/// @brief parameter constructor44Triangle(const Position& positionA, const Position& positionB, const Position& positionC);4546/// @brief destructor47~Triangle();4849/// @brief get triangle boundary50const Boundary& getBoundary() const;5152/// @brief get shape boundary53const PositionVector getShape() const;5455/// @brief check if the given position is within this triangle56bool isPositionWithin(const Position& pos) const;5758/// @brief check if the given position is FULL within this triangle59bool isBoundaryFullWithin(const Boundary& boundary) const;6061/// @brief check if the given shape is within or intersect with this triangle62bool intersectWithShape(const PositionVector& shape) const;6364/// @brief check if the given shape is within or intersect with this triangle65bool intersectWithShape(const PositionVector& shape, const Boundary& shapeBoundary) const;6667/// @brief check if the given circle intersect with this triangle68bool intersectWithCircle(const Position& center, const double radius) const;6970// @brief triangulate using Ear Clipping algorithm71static std::vector<Triangle> triangulate(PositionVector shape);7273/// @brief equalityoperators74bool operator==(const Triangle& other) const;7576/// @brief inequality operator77bool operator!=(const Triangle& other) const;7879private:80/// @name functions used for triangulation81/// @{82/// @brief check if the given position is within this triangle83static bool isPositionWithin(const Position& A, const Position& B, const Position& C, const Position& pos);8485/// @brief Check if the triangle (A, B, C) is an ear86static bool isEar(const Position& a, const Position& b, const Position& c, const PositionVector& shape);8788/// @brief calculate cross product of the given points89static double crossProduct(const Position& a, const Position& b, const Position& c);9091/// @}9293/// @name functions used for check if a shape intersect with the triangle94/// @{95/// @brief Compute the orientation of ordered triplet (p, q, r)96int orientation(const Position& p, const Position& q, const Position& r) const;9798/// @brief check if point q lies on segment pr99bool onSegment(const Position& p, const Position& q, const Position& r) const;100101/// @brief check if two line segments (p1,q1) and (p2,q2) intersect102bool segmentsIntersect(const Position& p1, const Position& q1, const Position& p2, const Position& q2) const;103104/// @brief check if a line segment (p1, p2) intersects this triangle105bool lineIntersectsTriangle(const Position& p1, const Position& p2) const;106107/// @}108109/// @brief function to check if line between posA and posB intersect circle110bool lineIntersectCircle(const Position& posA, const Position& posB, const Position& center, const double radius) const;111112/// @brief first triangle position113Position myA = Position::INVALID;114115/// @brief second triangle position116Position myB = Position::INVALID;117118/// @brief third triangle position119Position myC = Position::INVALID;120121/// @brief triangle boundary122Boundary myBoundary;123};124125126