cross2edges2
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Analytical Geometry
Introduced first in SolidGeometry 1.0, Creation date: 2012-05-12, Last change: 2025-09-14
calculates in 2D the crossing point of two straight lines
Description
This procedure is using rref of matlab for solving a equation system.
See Also: cross4P
, cross2edges
Example Illustration
Syntax
[cp,ka,kb,kd]=cross2edges2(pa,na,pb,nb)
Input Parameter
pa: | | point a |
na: | | direction vector a |
pb: | | point b |
nb: | | direction vector b |
Output Parameter
cp: | | crossing point |
ka: | | factor of direction vector a |
kb: | | factor of direction vector a |
kd: | | +1 == infinity solutions, -1; no solution; 0 there is a solution |
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 function calculates the crossing point of two straight lines in 2D using the reduced row echelon form (rref) of a matrix. It is part of the SolidGeometry library.
Input Parameters
- pa: A point on line a.
- na: The direction vector of line a.
- pb: A point on line b.
- nb: The direction vector of line b.
Output Results
- cp: The crossing point of the two lines.
- ka: The factor of the direction vector a.
- kb: The factor of the direction vector b.
- kd: Status indicator: +1 for infinite solutions, -1 for no solution, 0 for a single solution.
Algorithm Steps
- Check the dimension of
pa. If it has more than one column, use the transpose of the direction vectors and the difference of points to form a matrix. Otherwise, use them as they are.
- Apply the
rref function to the matrix to solve the system of equations.
- Initialize
ka, kb, cp, and kd with default values.
- Check the conditions of the matrix
K to determine the values of ka, kb, and cp:
- If the first row's first element is 1, calculate
ka and the crossing point cp using pa and na.
- If the second row's second element is 1, calculate
kb and the crossing point cp using pb and nb.
- If the first row's second element is not zero, calculate
kb and the crossing point cp using pb and nb, and set kd to 1.
- If the second row's second element is zero and the third element is 1, set
cp to empty, ka and kb to NaN, and kd to -1.
- If no output arguments are specified, plot the lines and the crossing point using the
SGfigure function and related plotting functions.
Algorithm explaination created using ChatGPT on 2025-08-19 07:02. (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