In-Place Offset Scaling of Polyline Polygons
@[toc]
Effect to be generated
The basic principle of hanging pits or sumps is to generate a circle of walls along the outside of the slab boundary for blocking.
Two methods for in-situ scaling of polyline polygons
One is the method in Zhou Peide’s Computational Geometry - Algorithm Design and Analysis (Third Edition), and the other is the method cited from Calculation Method of Polyline Parallel Lines. Finally, the second method solved the project problem, but since I wrote both algorithms, I analyzed both. This situation may be encountered in the future, so it is convenient to check back.
6.10 Polygon Enlargement, Reduction and Movement P309
The textbook records a method: make vectors from a point inside the closed polygon to each point, and offset based on the vector value to the outside by a specified distance. Values needed to be calculated:
- Vector v between polygon internal point and boundary point
- The offset value is the perpendicular distance between two parallel line segments, so the actual length needs to be calculated when encountering oblique line segments.
c# implementation
1 | /// <summary> |
Disadvantages
This method is not suitable for complex slab boundaries, but it can be used for convex hull sets. It is relatively simple to understand, but needs to add quadrant addition and subtraction. Those who are interested can verify the book details according to the catalog.
Analysis
The first picture shows that most of it is inaccurate. The reason is that offsetting from the center point to the boundary direction will result in incorrect details. The lower boundary here needs to be offset to both sides separately, but a collective offset of convex corners occurs. So in actual projects, there will be cases where project hanging pit generation is incorrect.
Vector Scaling Method
In fact, the first method also uses vectors for modification, but to distinguish it, I casually called it a name. Original link, added my own explanation and c# code here.
Algorithm Analysis
- Two groups of offset line segments can form a rhombus.
- We can use trigonometric functions to calculate the length of one side.
- According to the ratio of unit vector to length, the length of center PiQi can be calculated.
- Input: Actual offset distance, boundary point collection
- Output: Offset point collection
Algorithm Steps
- Calculate unit vectors normal v1, normal v2 based on point collection
- Organize formula 1:
|a X b| = |a|*|b|*sin(θ) - A calculation formula for the angle can be obtained, but since ∠θ is collinear with another angle, according to the theorem, it can be deduced that
sin(Π - θ) = sin(θ) - According to 3 and h distance, the length of the rhombus side in the v2 direction can be calculated through trigonometric functions. Lb is the length of the rhombus side, L represents h, that is:
L/Lb = sin(Π - θ) and sin(Π - θ) = sin(θ) - Organize formulas 2 and 3 to obtain the final formula:
Lb = L/|a X b|/|a|/|b| - Also because they are unit vectors, the modules of |a|, |b| are 1
- Finally, through vector addition formula:
Qi = Pi + L/|a x b| x (v1 + v2) - The direction of the vector represents reduction and enlargement. Mainly, the step L/sin(θ) in the original text may be confusing, so I explain it here.
c# Code
1 | public static CurveLoop OffsetPath(CurveLoop array, double k) |
Compared with the problem I encountered, this method has less code and better accuracy. The road to learning is bumpy and needs constant learning!
Revit API Method
If doing Revit development, if complex boundaries are not involved, you can use the CurveLoop.CreateViaOffset method inside, but this method will have errors, and expansion will become reduction in complex boundaries, as shown below




