Hello,
I have a diagonal line and would like to reduce it's length by 2 units. Is this done by trigonometry or are there utility functions available for computing points based on angle and length?
Thanks in advance!
Jr.
Here is an example of how you can do this. It doesn't matter if the line is straight or at any angle since it is using the segment length.
To test this code draw a single line say 6 inches long. Run the code and you will see that after it will now be 4 inches long.
Sub ShortenLine() Const dblLength As Double = 2 'Shorten by 2 inches Dim crv As Curve Set crv = ActiveShape.Curve crv.Segments.First.AddNodeAt (crv.Segments.First.Length - dblLength) / crv.Segments.First.Length, cdrRelativeSegmentOffset crv.Nodes.Last.Delete End Sub
Happy Coding,
-Shelby
With the offset having to be between 0 and 1, how would you do the opposite? Lengthen the line by 2 inches?
Add nod for first segment into position of it second node then move third node by 2 inchess.Curve.Segments.First.AddNodeAt 1then move third node by 2 inches (bias)
bias = 2 ''LN = Round(nN1.GetDistanceFrom(nN2), 3) X0 = xN1 - bias * (xN2 - xN1) / LN Y0 = yN1 - bias * (yN2 - yN1) / LNs.Curve.Nodes(3).SetPosition X0, Y0
Delete node 2s.Curve.Nodes(2).Delete Somehow
Thanks. What do I set nN1 and nN2 to? and xN1 and xN2 to?
LN here is segment length = diistance betwen nodes 1 and 2
I tried this, but I'm doing something wrong:
Sub lengthenline()Dim s As CurveSet s = ActiveShape.Curves.Segments.First.AddNodeAt 1Dim nN1 As NodeDim nN2 As Node
Set nN1 = s.Nodes(1)Set nN2 = s.Nodes(2)bias = 2xN1 = s.Nodes(1).PositionXyN1 = s.Nodes(1).PositionYxN2 = s.Nodes(2).PositionXyN2 = s.Nodes(2).PositionY
Ln = Round(nN1.GetDistanceFrom(nN2), 3)X0 = xN1 - bias * (xN2 - xN1) / LnY0 = yN1 - bias * (yN2 - yN1) / Lns.Nodes(3).SetPosition X0, Y0
'Delete node 2s.Nodes(2).Delete
End Sub
Sub lengthenline() Dim s As Curve Dim nN1 As Node Dim nN2 As Node Set s = ActiveShape.Curve Set nN1 = s.Nodes(1) Set nN2 = s.Nodes(2) bias = 2 xN1 = s.Nodes(1).PositionX yN1 = s.Nodes(1).PositionY xN2 = s.Nodes(2).PositionX yN2 = s.Nodes(2).PositionY s.Segments.First.AddNodeAt 1 Ln = Round(nN1.GetDistanceFrom(nN2), 3) X0 = xN2 + bias * (xN2 - xN1) / Ln Y0 = yN2 + bias * (yN2 - yN1) / Ln s.Nodes(3).SetPosition X0, Y0 s.Nodes(2).Delete