crossz
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Analytical Geometry
Introduced first in SolidGeometry 1.0, Creation date: 2012-05-11, Last change: 2025-09-14
calculates in 2D only the z-part of the cross product and handles values near zero
Description
ATTENTION!!!!!!! MAKES SENSE ONLY in 2D
See Also: tangent2circ
, cross2circ
, crosscircline
, PLof3dist
, PLchordof2PR
, PLcross2Lines
Example Illustration
Syntax
[z,s]=crossz(pa,pb)
Input Parameter
pa: | | vector a |
pb: | | vector b |
Output Parameter
z: | | z value of the cross product |
s: | | sign of (z) |
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, crossz, calculates the z-component of the cross product of two 2D vectors, pa and pb. It is designed to work specifically in 2D space and is part of the SolidGeometry library.
Input Parameters
- pa: A 2D vector representing the first vector in the cross product.
- pb: A 2D vector representing the second vector in the cross product.
Output Results
- z: The z-component of the cross product of vectors
pa and pb.
- s: The sign of
z, indicating the direction of the cross product. It is -1 for negative, +1 for positive, and 0 if z is zero.
Algorithm Steps
- Define a threshold value,
thr, set to 1e-12 to handle numerical precision issues.
- Calculate the z-component of the cross product using the formula:
z = pb(2)*pa(1) - pb(1)*pa(2).
- Check if
z is within the threshold range of zero. If so, set z to zero.
- Determine the sign of
z:
- If
z is less than zero, set s to -1.
- If
z is greater than zero, set s to +1.
- If
z is zero, set s to 0.
- If no output arguments are specified, visualize the vectors using a plot:
- Normalize the vectors
pa and pb and scale them for visualization.
- Display an annotation indicating the direction of the cross product: "positive = ccw | negative == cw".
Algorithm explaination created using ChatGPT on 2025-08-18 23:54. (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