Proctor Posted March 11, 2010 Posted March 11, 2010 Hello: If you look at the left most pic attatched, I have created a blue perpendicular line to the red line. The perp line is going in the direction I want - which is towards the black line; however, sometimes the perpendicular line will run the opposite direction - away from the black line (see right most pic). here's my code: myLine3d = New Geometry.Line3d(myMainLine.StartPoint, myMainLine.EndPoint) 'if the perp line is going in the wrong direction, i'll try to put a negative number to multiply by (e.g. -20) and then it will go in the right direction. START_X = myMainLine.StartPoint.Subtract(myLine3d.Direction.Negate.GetPerpendicularVector.MultiplyBy(20)) 'Create perpendicular line of MainLine perpLine = New Line(myIncrementPtOfMainLine, START_X) How can I determine if I should multiply by a positive or negative number in order to make the perp line go towards the black line? Thanks, Proctor Quote
JohnM Posted March 12, 2010 Posted March 12, 2010 not sure about the rest of your code. can you pick the line or lines and get the angle in lisp you would use getpoint and getpoint then get the angle of the 2 points. or get the start or end points of the 2 lines then get the angle or use a selection set filtering for blac and red lines and get the angle if your program draws the 2 lines then you have the info needed Quote
Proctor Posted March 12, 2010 Author Posted March 12, 2010 JohnM - Thanks for your reply. Currently, I am asking the user to select both the lines(red and black)...so I can get their angles; however, can you please explain to me how I can use the angles to get the correct direction to go in for my perp? Thanks again for your help, Proctor Quote
JohnM Posted March 12, 2010 Posted March 12, 2010 I don’t use .net but I can tell you how I would figure it out in my head. I also don’t know what all your program does so it would help to know more. Could you explain what your program does in total or post it. Are the 2 lines always vertical? Do the 2 lines share any start, end or mid point that are aligned? Is the line always from the mid point then through the mid point of the other line? How is the user selecting the lines, Red then black or black the red or any choice they want? If you will always draw a line at 0 or 180 degrees you can us the angle info to round to the correct direction. Example if the user picks the line on the left then the one on the right then you get the angle (say its 45 degrees) you write a bit of code to say if the angle is less then 90 and greater than 270 new angle = 0 or the reverse for the other direction if the angle is greater than 90 and less than 270 new angle = 180 Quote
SEANT Posted March 12, 2010 Posted March 12, 2010 You don’t directly mention whether this routine will accommodate 3D or not but this line: myLine3d = New Geometry.Line3d(myMainLine.StartPoint, myMainLine.EndPoint) suggests that it may. If that is the case (and its not a bad idea to allow for 3d in either case) then I’d be tempted to use this sequence of events. myMainLine3d = New Geometry.Line3d(myMainLine.StartPoint, myMainLine.EndPoint) myNextLine3d = New Geometry.Line3d(myNextLine.StartPoint, myNextLine.EndPoint) [u]//Comment Determine where on mainline a perpline should originate (end, middle, etc.) and set it to perpPoint.//Comment[/u] myPlane3D = New Plane(perpPoint, myMainLine3d.Direction) to get a perp point on next line. perpNextPt = myNextLine3d.IntersectWith(myPlane3D) Now a line can be created from perpPoint to perpNextPt. Quote
Kerry Brown Posted March 12, 2010 Posted March 12, 2010 Posting the full code and the drawing that demonstrates the issue would be the best way to get this resolved. There are so many unknowns in the mix that answering the question with certainty is next to impossible. Quote
Danielm103 Posted March 13, 2010 Posted March 13, 2010 FYI There is a bug in AutoCAD 2009 && .NET 3.5sp1 that can cause some Vector methods to return incorrect results. see http://www.theswamp.org/index.php?topic=24462.0 http://discussion.autodesk.com/forums/thread.jspa?threadID=685493 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.