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
Thanks Shelby,
I've been trying to do it with calculating a new X and Y using the nodes and the angle of a line segment (X3 = ChangeInX + Cos(angle) * 2 , Y3 = changeInY + sin(angle) * 2 etc.), but I must be doing something wrong. Somehow it changes the angle. Maybe I'll try to post the code later, but can you change the nodes by assigning a different X & Y? Your code is definitely easier to read though. Thanks!
Yep, say I wanted to move the first node you could so something like this:
crv.Nodes.First.SetPosition x, y