Hi Tom,
I checked your code very quickly (before another crazy busy day will start ;-)
[quote user="Tom"]The coding is quite long...[/quote]
No problem, it's not so long. Bigger problem is your code is not well structured and can be refactored to be better. I recommend to follow at least these rules:
- Simple rule: If a method or function is longer than a screen (lets say about 20 - 30 lines), it's too long and should be refactored to more individual functions.
- No so simple rule: Every function should do one and only one thing. If you will follow this rule, you will usually fulfil also the first rule.
[quote user="Tom"]...so i have uploaded.[/quote]
Great. Very often it's much better to load mvba than to think about posted code snippet.
[quote user="Tom"]Errors occur when bearing of line is 90/180/270/360 degrees [/quote]
What I see in your code:
slopeA = (elem.AsLineElement.EndPoint.Y - elem.AsLineElement.StartPoint.Y) / (elem.AsLineElement.EndPoint.X - elem.AsLineElement.StartPoint.X) slopeB = -1 / slopeA
This code is "bad math", because in some situations the result (slopeA) will be 0. And it's not possible to divide by 0, because the result is infinity and the code will crash. Right solution is to use rotation matrix to handle rotation angle, because the matrix is able to work with any angle.
With regards,
Jan