Hi,
I was expecting a drawing with sample points to disambiguate '
Above' from left or right regarding the local orientation.
Basically any line-art has no width, any point along the polyline will be on the vectored data.
And thus on the central line with Lineweights or custom widths.
Pen sizes are to render visible line-art, a vector has an infinite small thickness and that doesn't show on screen/paper.
One can explode polylines with custom widths to outer contours (A hybrid format and there are known flaws).
One
can not explode Lineweights to contours right out the box.
There should be a way because Lineweights are rendered as solid filled contours where the contours are again vectors.
A polyline has an overall length (Also disregarding pen size).
It is then as simple as stepping the step-size and retrieving each next position until you are past the end of the entity.
Getting points along the polyline at a certain distance from the start point:
Code: Select all
var polyEntity; // A drawing polyline entity queried from the document.
var distance; // For example N times a step-size
var points = polyEntity.getPointsWithDistanceToEnd(distance, RS.FromStart);
Remind that this returns an array given that you can use
RS.FromAny aka points from both ends.
One should validate what is returned as being a valid RVector.
'
Above the polyline' could be as simple as adding an offset to the Y coordinate.
But translating the points upwards can still be on the polyline for vertical segments.
'
Above' could also mean left or right and this is according the polyline direction.
Your example polyline changes 2 times in main horizontal direction ...
... Remind that from our perspective left from the entity may be both up or down.
Left in perceptive of the polyline direction may be left or right.
The amount of steps is based on your polyline length and the step-size:
Code: Select all
var stepSize = 10; // Given step-size
var steps = Math.floor(polyEntity.getLength() / stepSize);
for (var i=0; i<steps; i++) {
distance = stepSize * i;
// ...
// Code for each point
// ...
}
Remark that I don't use
distance = distance + stepSize or
distance += stepSize each iteration.
> You should avoid running sums in Floating Point arithmetic.
Also remark that I used
for (var i=0 what includes the startpoint,
for (var i=1 does not.
Due to
Math.floor we may or may not include the endpoint but we will never traverse it.
Excluding the endpoint is by verifying the point at active distance against the entity endpoint with some degree of tolerance.
Code: Select all
// Don't include entity endpoint:
if (point.equalsFuzzy2D(polyEntity.getEndPoint()) { // Fuzzy compare with RS.PointTolerance = 1e-9
// Exit for loop:
break;
}
To get the nearest segment related to the position and the orientation of this segment:
Code: Select all
var segmentId = polyEntity.getClosestSegment(point);
var segment = polyEntity.getSegmentAt(segmentId);
if (isLineShape(segment)) {
var ori = segment.getAngle();
}
You then translate the point by an orthogonal vector to the left (
ori + Math.PI/2) or to the right (
ori - Math.PI/2).
Remark that I excluded arc segments, for these the offset vector is oriented to/from the arc shape center.
The offset vector magnitude is the required offset.
The offset should account for half the Lineweight:
Code: Select all
var halfPen = polyEntity.getLineweight() / 200; // divided by 100, divided by 2
Remind that:
- Lineweights are in 1/100mm and custom widths are in document units, a further scaling on document units may be required for Lineweights.
- Lineweights can also refer to
byLayer or
byBlock and then you need to resolve that.
- For points (almost) coinciding with nodes the closest segment is the segment before the node.
> Can be tricky with closed polylines.
- Lineweights are rendered as a round pen, custom widths as a flat pen, the offset at nodes is thus quite different.
- The local custom width depends on A: a global width
OR B: a local width depending the segment start and end widths.
For now this answer is not closed form, please elaborate on 'above' or give examples.
But maybe you just require the offset contour of line-art with a certain pen width.
Regards,
CVH