isintriangle2
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Analytical Geometry
Introduced first in SolidGeometry 1.0, Creation date: 2012-07-13, Last change: 2025-09-14
returns whether a point is in a triangle
Description
from http://www.blackpawn.com/texts/pointinpoly/default.html
See Also: , issameside
Example Illustration
Syntax
b=isintriangle2(p,A,B,C)
Input Parameter
p: | | point to test |
A: | | Point A of triangle |
B: | | Point B of triangle |
C: | | Point C of triangle |
Output Parameter
Copyright 2012-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This algorithm determines if a point p is inside a triangle defined by points A, B, and C. The function isintriangle2 returns a boolean value b indicating whether the point is inside the triangle.
Input Parameters
- p: The point to test, represented as a coordinate pair (x, y).
- A: The first vertex of the triangle, represented as a coordinate pair (x, y).
- B: The second vertex of the triangle, represented as a coordinate pair (x, y).
- C: The third vertex of the triangle, represented as a coordinate pair (x, y).
Output
- b: A boolean value.
true if the point p is inside the triangle, false otherwise.
Algorithm Steps
- The function
issameside is used to check if the point p is on the same side of the line formed by two triangle vertices as the third vertex.
- The function
issameside is called three times:
- First, to check if
p and A are on the same side of the line formed by B and C.
- Second, to check if
p and C are on the same side of the line formed by A and B.
- Third, to check if
p and B are on the same side of the line formed by A and C.
- If all three checks return
true, the point p is inside the triangle, and the function returns true. Otherwise, it returns false.
Algorithm explaination created using ChatGPT on 2025-08-18 22:32. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21