plotrulerline
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Visualization
Introduced first in SolidGeometry 5.2, Creation date: 2022-05-14, Last change: 2025-09-15
draws an simple ruler between two points in 2D
See Also: tplotruler
Example Illustration
Syntax
plotrulerline(P1,P2,[nam])
Input Parameter
P1: | | Start Point or [P1;P2] |
P2: | | End Point |
nam: | | Name, for instace "D=" |
Copyright 2022-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, plotrulerline, is designed to draw a simple ruler line between two points in 2D space. It is part of the SolidGeometry library and was introduced in version 5.2.
Input Parameters
- P1: This is the start point of the line. It can also be a matrix containing both start and end points, i.e., [P1; P2].
- P2: This is the end point of the line. If not provided, it is extracted from P1 when P1 is a matrix.
- nam: An optional name or label for the ruler, such as "D=".
Algorithm Steps
- Extract
P2 from varargin if not directly provided. If P2 is empty, assume P1 contains both points.
- Ensure both
P1 and P2 are 3D by adding a zero z-coordinate if they are 2D.
- Calculate the center point
CP as the midpoint between P1 and P2.
- Determine the scale factor
s based on the current axis scaling.
- Compute the direction vector
dv and its magnitude d. Normalize dv to get the unit vector ev.
- Calculate the orthogonal vector
ov using a transformation matrix T.
- Set the line length
ll to the minimum of d and 0.7.
- Determine extended points
OP1 and OP2 for drawing purposes.
- Round the distance
d to the nearest 0.05 for display.
- Format the distance as a string
txt, appending nam if provided.
- Check the ratio
s/d to decide the drawing method:
- If
s/d < 100, draw short lines at P1 and P2, and connect CP to both points with lines.
- Otherwise, draw extended lines from
OP1 to P1 and OP2 to P2, and place the text at P2.
- Calculate the angle
w for text rotation based on the direction vector.
- Set the rotation of the text to align with the line.
Algorithm explaination created using ChatGPT on 2025-08-19 07:15. (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