See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: vlax routine perpendicular lines along polyline.

  1. #1
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,089
    Login to Give a bone
    0

    Default vlax routine perpendicular lines along polyline.

    I am working on this routine to draw perpendicular along a polyline. This routine will be creating some 3d geometry based on a couple of 3D pick points. The problem I haven't figured out just yet is how do I calculate the perpendicular angle at a specified distance along the polyline.

    I have attached the code that will place a POINT entity at the selected places. The inserted point will be replaced with some code to draw the necessary 3d geometry. I already have the 3d geometry code written. I just need to calculate the perpendicular angle of the polyline. The polyline will most likely contain some kind of arc and possible more than one arc and a tangent.

    Code:
    (defun C:TEST ()
      (setq	ENTITY	    (entget (car (entsel "\nSelect alignment: ")))
    	VLAX-ENTITY (vlax-ename->vla-object (cdr (assoc -1 ENTITY)))
    	VLAX-LENGTH (if	(vlax-property-available-p VLAX-ENTITY 'length)
    		      (vlax-get-property VLAX-ENTITY 'length)
    		    )
      )
      (setq OSM (getvar "osmode"))
      (if VLAX-LENGTH
        (progn
          (setq INCREMENT (fix (/ VLAX-LENGTH 3.0)) ;_ Arbetrary length of 3.0 for testing.
    	    INCREMENT (/ VLAX-LENGTH INCREMENT)
          )
          (setvar "osmode" 0)
          (repeat (- (fix (/ VLAX-LENGTH 3.0)) 1)
    	(setq VLAX-LENGTH (- VLAX-LENGTH INCREMENT))
    	(setq TempPoint (vlax-curve-getpointatdist VLAX-ENTITY VLAX-LENGTH))
    	(command "_.point" TempPoint)
    						  ; This is the place in the code I need to calculate
    						  ; the perpendicular angle of the polyline.  As you can
    						  ; see this angle will change based on where along the
    						  ; polyline the point is located.
          )
        )
      )
      (vlax-release-object VLAX-ENTITY)
      (setvar "osmode" OSM)
    )
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  2. #2
    AUGI Addict sinc's Avatar
    Join Date
    2004-02
    Location
    Colorado
    Posts
    1,986
    Login to Give a bone
    0

    Default Re: vlax routine perpendicular lines along polyline.

    vlax-curve-getFirstDeriv will return a direction vector indicating the direction of the polyline at the given point. If the point is in a curve, the direction vector is the tangent at that point. You will need to rotate the bearing ±90° yourself to get the crossing vector.

    Working with polylines can get a little tricky, since the polyline has a certain direction. The vector returned by vlax-curve-getFirstDeriv is based on the polyline direction, which is determined by how the polyline is created.

    (But unlike arcs, at least polylines HAVE a direction... Arcs always go counter-clockwise, which is sometimes a royal pain.)

  3. #3
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,089
    Login to Give a bone
    0

    Default Re: vlax routine perpendicular lines along polyline.

    Quote Originally Posted by richards.64879
    vlax-curve-getFirstDeriv will return a direction vector indicating the direction of the polyline at the given point. If the point is in a curve, the direction vector is the tangent at that point. You will need to rotate the bearing ±90° yourself to get the crossing vector.

    Working with polylines can get a little tricky, since the polyline has a certain direction. The vector returned by vlax-curve-getFirstDeriv is based on the polyline direction, which is determined by how the polyline is created.

    (But unlike arcs, at least polylines HAVE a direction... Arcs always go counter-clockwise, which is sometimes a royal pain.)
    Thanks for that. I'm still learning the vlax- routines. The help file wasn't very helpful on this topic so I brought it here.

    I know about the arcs. The routine I am modifying is for arcs. I was just tired of having to pick each arc when I could make them into a polyline and do the same thing.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  4. #4
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    1

    Default Re: vlax routine perpendicular lines along polyline.

    It depends on what kind of object you are calculating, line , arc, ellipse . . .
    Here is a way point :
    Code:
    (setq Ent (entsel "Select the polyline curve : " ) )
    (vl-load-com )
    (setq VlaObj (vlax-ename->vla-object (car Ent )) )
    (setq MyDist 250 ) ; <-- Your distance input
    (setq Param (vlax-curve-getParamAtDist VlaObj MyDist ) )
    line :
    (setq Ang (- (* (/ (Angle (vlax-curve-getFirstDeriv VlaObj Param ) (vlax-curve-getSecondDeriv VlaObj Param ) ) pi ) 180 ) 90 ) )
    arc :
    (setq Ang (- (* (/ (Angle (vlax-curve-getFirstDeriv VlaObj Param ) (vlax-curve-getSecondDeriv VlaObj Param ) ) pi ) 180 ) 45 ) )
    : ) Happy Computing !

    kennet
    Last edited by kennet.sjoberg; 2006-01-24 at 11:01 PM.

  5. #5
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,089
    Login to Give a bone
    0

    Default Re: vlax routine perpendicular lines along polyline.

    Quote Originally Posted by kennet.sjoberg
    It depends on what kind of object you are calculating, line , arc, ellipse . . .
    Here is a way point :
    Code:
    (setq Ent (entsel "Select the polyline curve : " ) )
    (vl-load-com )
    (setq VlaObj (vlax-ename->vla-object (car Ent )) )
    (setq MyDist 250 ) ; <-- Your distance input
    (setq Param (vlax-curve-getParamAtDist VlaObj MyDist ) )
    line :
    (setq Ang (- (* (/ (Angle (vlax-curve-getFirstDeriv VlaObj Param ) (vlax-curve-getSecondDeriv VlaObj Param ) ) pi ) 180 ) 90 ) )
    arc :
    (setq Ang (- (* (/ (Angle (vlax-curve-getFirstDeriv VlaObj Param ) (vlax-curve-getSecondDeriv VlaObj Param ) ) pi ) 180 ) 45 ) )
    : ) Happy Computing !

    kennet
    Thanks kennet. That gives me something to work with. Why is the arc at 45 degrees instead of 90 degrees?
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  6. #6
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: vlax routine perpendicular lines along polyline.

    Quote Originally Posted by Opie
    Thanks kennet. That gives me something to work with. Why is the arc at 45 degrees instead of 90 degrees?
    That confuse me to, and I do not really know why, but for me it works that way. . and then you have the ellipse.

    You have to test before you permanent the code, I may be wrong in this case.

    : ) Happy Computing !

    kennet

  7. #7
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,104
    Login to Give a bone
    1

    Default Re: vlax routine perpendicular lines along polyline.

    The first derivative will give the slope at any point on a curve that is continuous, but in the case of a vertex, where the curve is not continuous, it will not. One suggestion is to use the vlax-curve-getpointatdist function to get the point 0.001 in front of your point and 0.001 behind your point and then calculate the angle between the two and then add pi/2 to get the angle of your perpendicular line. Using the polar command it would be easy to draw the line.

    Another way is to determine the slope of one segment using the derivative and the slope of the next segment using the derivative and then average them and then add pi/2.

    Peter

  8. #8
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,089
    Login to Give a bone
    0

    Default Re: vlax routine perpendicular lines along polyline.

    Thanks kennet. Hopefully with this routine I won't need to worry about an ellipse since we don't use them very often.

    Thanks for the insight, Peter. That explains it a little more. I am still confused with it but I'll figure it out with time.

    Both of you are an asset.

    Richard
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  9. #9
    AUGI Addict sinc's Avatar
    Join Date
    2004-02
    Location
    Colorado
    Posts
    1,986
    Login to Give a bone
    0

    Default Re: vlax routine perpendicular lines along polyline.

    WARNING: vlax-curve-getSecondDeriv returns 0 for lines and line segments.

  10. #10
    AUGI Addict sinc's Avatar
    Join Date
    2004-02
    Location
    Colorado
    Posts
    1,986
    Login to Give a bone
    0

    Default Re: vlax routine perpendicular lines along polyline.

    Quote Originally Posted by peter
    The first derivative will give the slope at any point on a curve that is continuous, but in the case of a vertex, where the curve is not continuous, it will not. One suggestion is to use the vlax-curve-getpointatdist function to get the point 0.001 in front of your point and 0.001 behind your point and then calculate the angle between the two and then add pi/2 to get the angle of your perpendicular line. Using the polar command it would be easy to draw the line.

    Another way is to determine the slope of one segment using the derivative and the slope of the next segment using the derivative and then average them and then add pi/2.

    Peter
    This is a little confusing, but it raises a valid point.

    I don't think Peter means "continuous" - by definition, a polyline must be continuous. But for a polyline, the derivatives at each vertex are based on the following segment of the polyline (the "course out" of the vertex, so to speak). So a problem arises when there is an angle point at the vertex (i.e., the "course in" and the "course out" of the vertex are different).

    As an example, assume you have a polyline with a bunch of line segments (no arcs). The first derivative at param=4.0 would be the same as the first derivative at param=4.01, but not the same as the first derivative at param=3.99. If the segment between param=4.0 and param=5.0 is an arc segment, the derivatives at param=4.0 yield tangent and radial vectors at the beginning of the arc segment. But in either case, the derivatives at param=4.0 are for the "course out", or the segment between param=4.0 and param=5.0. The only way to determine the values for the "course in" is to get the derivatives at a point where the param<4.0 by just a hair.

    So, Peter's method will split the difference between the "course in" and the "course out", which may or may not be exactly what you want. The only thing I would add is you may want to make sure you calculate points around your vertex using distance methods, and not parameters. For polylines, the distance between parameters varies, depending on the length of the polyline segments.

Page 1 of 2 12 LastLast

Similar Threads

  1. Fillet perpendicular lines
    By Raudel Hinojosa Sr in forum AutoLISP
    Replies: 2
    Last Post: 2015-08-07, 06:40 AM
  2. Looking for routine...Polyline box around a polyline
    By iacevedo270202 in forum AutoLISP
    Replies: 4
    Last Post: 2011-04-06, 06:20 PM
  3. Extension Lines on Arc Length Dimension Always Perpendicular
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2009-02-01, 05:08 PM
  4. Drawing perpendicular to a 3D polyline
    By sbullinger in forum AutoCAD General
    Replies: 12
    Last Post: 2008-08-15, 07:14 PM
  5. Non-parallel/perpendicular grid lines
    By DanielleAnderson in forum Revit Architecture - General
    Replies: 2
    Last Post: 2006-11-16, 07:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •