Convex or concave polyline

Convex or concave polyline

devitg
Advisor Advisor
3,472 Views
28 Replies
Message 1 of 29

Convex or concave polyline

devitg
Advisor
Advisor

Hi , how it can be determinate if the sample polylines are   convex or concave .? 

I need to put a Convex or Concave text at each one , at it's  mid point . 

Of course, view direction is from up to down. 

Such polyline have no arcs on it. 

Please see attached DWG 

Thanks in advance. 

 

0 Likes
Accepted solutions (3)
3,473 Views
28 Replies
Replies (28)
Message 2 of 29

CodeDing
Advisor
Advisor

@devitg ,

 

To answer your question, we need more "default" parameters than just knowing that it will always be top-down.

Is Convex always going Up (North)? and concave always going down (South)? because, if we maintain the top-down view and rotate 180 degrees, the items are reversed. Perhaps concave is always RIGHT relative from Start to Finish and convex is always LEFT relative from start to finish?

 

Can you please provide more information?

 

EDIT:

We can take the Average X & Y values from ALL of the vertices to determine the side that the 'bulge' is relative from the starting and ending point. But, this also assumes that your Polylines will NOT cross the line between Start & End (or at least majority of bulge points average more to one side than another). And again, we need more information because merely knowing the side of the bulge does not tell us if concave or convex based on the guidelines you have already provided.

 

Best,

~DD

0 Likes
Message 3 of 29

doaiena
Collaborator
Collaborator

In your example, both polylines start on the left side and go towards X+. If that is always the case, just check if the vertices are going in a clockwise direction or CCW.

Here is a function from Lee_Mac that will help you:
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/polyline-clockwise-or-counter-clockw... 

 

CW = Convex

CCW = Concave

0 Likes
Message 4 of 29

Kent1Cooper
Consultant
Consultant
Accepted solution

If they always represent just an approximation of a single-direction curve [no reversing direction], open-ended, and generally horizontally oriented so that it's clear what the direction of curvature is when viewed from "above," try this [in very simplest terms]:

 

(defun C:PCCA ; = Polyline approximation of single Curve Concave/convex from Above
  (/ pl)
  (setq pl (car (entsel "\nSingle-curve-approximation Polyline in generally horizontal orientation: ")))
  (prompt
    (strcat
      "\nThe Polyline is "
      (if
        (> ; compare Y coordinates of:
          (cadr (mapcar '/ (mapcar '+ (vlax-curve-getStartPoint pl) (vlax-curve-getEndPoint pl)) '(2 2 2))); midpoint between ends
          (cadr (vlax-curve-getPointAtDist pl (/ (vlax-curve-getDistAtPoint pl (vlax-curve-getEndPoint pl)) 2))); midpoint of Polyline
        ); >
        "CONCAVE"
        "CONVEX"
      ); if
      " from above."
    ); strcat
  ); prompt
  (princ)
); defun

 

It doesn't matter in which direction the Polyline was drawn.

 

It could, of course, be made to verify you picked the right kind of thing, draw in the Text/Mtext, etc.

Kent Cooper, AIA
Message 5 of 29

hak_vz
Advisor
Advisor
Accepted solution

Try this for your particular case.

(defun concon (e / ent pts m p1 p2 p3 mp ret)
	(setq ent (entget e))
	(while (setq m (assoc 10 ent) ent (cdr (member m ent)))(setq pts (cons (cdr m) pts)))
	(setq p1 (nth 0 pts) p2 (nth (fix (/ (length pts) 2.0)) pts) p3 (last pts))
	(setq mp (mapcar '* (mapcar '+ p1 p3) '(0.5 0.5)))
	(if (> (cadr mp) (cadr p2)) (setq ret "concave")(setq ret "convex"))
	ret 
)

 

General algorithm:  p1 is a startpoint, p2 midpoint and p3 end point of an arc. Depending on how point p2 is positioned regarding to midpoint of a line connecting p1 and p3 arc is either convex or concave.

If y (p2) > y(mp) curve is convex, y (p2) < y(mp) curve is concave.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 6 of 29

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

... try this ....

It doesn't matter in which direction the Polyline was drawn.

....


And, in fact, it would work on an Arc or Spline or partial Ellipse, too, with the same conditions.

Kent Cooper, AIA
0 Likes
Message 7 of 29

devitg
Advisor
Advisor

Hi all you  helpers , I will test it , seem to be Ok . I let you know any news. Thanks again 

 

0 Likes
Message 8 of 29

john.uhden
Mentor
Mentor
Accepted solution

I don't know why you have so many vertices when the shapes are apparently arcs, but

Either way it seems to me that if the midpoint (i.e. middle distance) is higher (Y axis) than the ends, then it is convex, and vice versa for concave.  Now if your UCS isn't World you'll have to do comparisons using the trans function.  Then again, if you DView;Twist it gets more confusing, but at least you could temporarily set your UCS to View.

Getting the midpoint of a polyline would go something this (off the top of my head)

(defun @midpoly (e)
  (vlax-curve-getpointatdist e
    (* 0.5
      (+
        (vlax-curve-getdistatpoint e (vlax-curve-getstartpoint e))
        (vlax-curve-getdistatpoint e (vlax-curve-getendpoint e))
      )
    )
  )
)

Hmm, it can get more technical.  You really have to compare the Y value of the actual midpoint (using @midpoly) to the midpoint between the startpoint and endpoint...

(defun @midp (p1 p2)
  (mapcar '* '(0.5 0.5 0.5)(mapcar '+ p1 p2))
)

 

John F. Uhden

Message 9 of 29

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

.... if the midpoint (i.e. middle distance) is higher (Y axis) than the ends, then it is convex, and vice versa for concave.  ....  You really have to compare the Y value of the actual midpoint (using @midpoly) to the midpoint between the startpoint and endpoint....


In their sample drawing, the midpoint in the convex one is higher than one end, but slightly lower than the other.  So your second description of the situation is more appropriate, and is exactly what my suggestion in Message 4 does.

Kent Cooper, AIA
0 Likes
Message 10 of 29

devitg
Advisor
Advisor

@john.uhdenwrote

 


I don't know why you have so many vertices when the shapes are apparently arcs, but 

It are part of a survey profile 

 

devitg_1-1614026542553.png

 

 

 

And to be more complicated the blue one is both concave and convex 

devitg_2-1614026636556.png

 

 

devitg_0-1614026375166.png

 

 

Right now I will test the suggested options  

 

0 Likes
Message 11 of 29

john.uhden
Mentor
Mentor
@Kent1Cooper
Are you saying I'm late to the party again?
I'm gonna start losing invitations. 😕

John F. Uhden

0 Likes
Message 12 of 29

john.uhden
Mentor
Mentor
Well, if those are existing survey points, the crew must not get much done
each day, taking shots every 2.5m. But the profile is very smooth, so the
road doesn't need reconstruction anyway. But if Argentina is anything like
the US then they'll rebuild the road if just the paint stripes are worn. 😕

John F. Uhden

0 Likes
Message 13 of 29

hak_vz
Advisor
Advisor

@devitgYou always say "Please attach one original section or part of it" but this time you didn't do it.

 

 

You can create segments of your polyline and extract bulge value for each segment. If bulge  is equal to 0 then segment is straight line, if not segment is an circular arc which positive or negative value defines if it is convex or concave.

 

 

 

(defun lwpoly_segs ( e / ent p1 pt bulge seg seglst)
(setq ent (entget e))
(cond (ent
         (if (= (logand (cdr (assoc 70 ent)) 1) 1)
           (setq p1 (cdr (assoc 10 ent)))
         )
         (while (setq ent (member (assoc 10 ent) ent))  
		   (setq seg   nil)
           (if (and pt bulge)
             (setq seg (list pt bulge))
           )
           (setq pt    (cdr (assoc 10 ent))
                 ent (member (assoc 42 ent) ent)
				 bulge (cdar ent)
				 
           )
           (if seg
             (setq seg (list (car seg)(cadr seg)pt)
                   seglst (cons seg seglst))
           )
         )
        )
  )
  (if p1 (setq seglst (cons (list pt bulge p1) seglst)))
  (reverse seglst)
)

 

Each segment is defined as a list (pt1 bulge pt2)

In case you need this

(defun circle_from_bulge (segment / p1 bulge p2 gamma cent phi r theta);
  (mapcar 'set '(p1 bulge p2) segment)
  (setq theta (* 4.0 (atan (abs bulge))))
  (setq r  (/ (/ (distance p1 p2) 2.0) (sin (/ theta 2.0))))
         (setq gamma (/ (- pi theta) 2.0)
               phi   (if (>= bulge 0)
                       (+ (angle p1 p2) gamma)
                       (- (angle p1 p2) gamma)
                     )
                cen    (polar p1 phi r)
         )
  (list cen r)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 14 of 29

devitg
Advisor
Advisor

@hak_vz  in this case there is no "arc" , just a polyline with no arc , 

Doing a multiple ASSOC for code 42 , give 

 

(0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0)

 

 

 

 

 

 

 

0 Likes
Message 15 of 29

john.uhden
Mentor
Mentor
Wait a second. If you're talking about a polyline segment that's of
similar size to @devitg's complex arc, then you don't have to reconstruct
anything. Just find the bulged segment and treat it like an arc. P1 and P2
are the beginning and end of the segment and the distances to use are the
distances at p1 and p2. It's the same math.

John F. Uhden

0 Likes
Message 16 of 29

devitg
Advisor
Advisor
@ hak_vz Please see my original post , I did as I always ask .

I upload the Sample.dwg
After it and following all post , I show my case in a big image.
First to show that some polylines are CONVEX and CONCAVE .
And then to show the whole work .
I test all solutions given and they work well


0 Likes
Message 17 of 29

devitg
Advisor
Advisor

@john.uhden 


@john.uhden wrote:
Well, if those are existing survey points, the crew must not get much done
each day, taking shots every 2.5m. But the profile is very smooth, so the
road doesn't need reconstruction anyway. But if Argentina is anything like
the US then they'll rebuild the road if just the paint stripes are worn. 😕

But if Argentina is anything like
the US then they'll rebuild the road if just the paint stripes are worn.  

NEVER 

Only is it are to have elections the rebuild it , only the paint stripes 

 

0 Likes
Message 18 of 29

Sea-Haven
Mentor
Mentor

It looks to me to be road reconstruction something I did for years, so trying to reproduce Vertical curve gradings that approximate both hi and Low point Vc's. For us it was a trial and error looking at cut fill values. This idea would be helpful giving a Vertical curve length starting point. Walk along the pline and compare 3 adjacent points adding VC length until 3 pts turn up or down. so get something like.

Ch 40 Vc = 50

Ch 90 Vc = 75

 

It should also take into account variation off a straight line comparing points so a curve is considered where diff on grade pt1-pt3 compare pt2 is less than  a value so considered a straight. 

 

Spent to many years doing asphalt overlays. This type of method is built in to Civil site design. It has options to automate this type of task. Devitg Happy to provide more info.

0 Likes
Message 19 of 29

john.uhden
Mentor
Mentor
So, do you guys design the paint stripes vertically too?
But of course... you use a 3D paint truck, right?😂
Though if there is a difference in elevation between the road and the
paint, then the auto manufacturers can sell a lot more cars each year, and
claim credit for replenishing barrier reefs with the junks. THAT is the
American way. 😕

John F. Uhden

0 Likes
Message 20 of 29

john.uhden
Mentor
Mentor
Oh, c'mon, Alan. We've all tried to match existing with perfect grades and
vertical curves only to have the politicians proclaim the need for
reconstruction, and they're thrilled to tell the taxpayers how their
spending is improving life, liberty, and the pursuit of happiness, even for
those who own only a bicycle, tractor, or oxen.
I doubt that Argentina is much different, and yes, especially at election
time.

John F. Uhden

0 Likes