Jump to content

Recommended Posts

Posted
(setq gct (osnap (vlax-curve-getStartPoint bm) "gcen"))

The above code line gives only closed polyline

How to find the geometric center of an open polyline and a single line

Posted
1 hour ago, maahee said:
(setq gct (osnap (vlax-curve-getStartPoint bm) "gcen"))

The above code line gives only closed polyline

How to find the geometric center of an open polyline and a single line

 

Only the geometric center is available for closed areas, since open polylines have no area and therefore no true center. If it’s just a line, the "geometric center” is the midpoint. 

  • Agree 1
  • Thanks 1
Posted

You can actually calculate it, here is the code (you can change it for your purposes):

 

(setq ptlist (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= (car x) 10))) (setq ent (entget (car (entsel "\nSelect the line:")))))) ;; point list
      sum_x 0
      sum_y 0
      vertices (cdr (assoc 90 ent)) ;; number of vertices for LWPOLYLINE
      )

(foreach pt ptlist
  (setq sum_x (+ sum_x (car pt))) ;; sum only the X vertices values
  )

(foreach pt ptlist
  (setq sum_y (+ sum_y (cadr pt))) ;; sum only the Y vertices values
  )

(setq sum_x (/ sum_x vertices) ;; dividing the total sum X by the number of vertices
      sum_y (/ sum_y vertices) ;; dividing the total sum Y by the number of vertices
      pt (list sum_x sum_y) ;; geometric center
      )

 

Below are the pictures with geometric center for open and closed polyline (picture 1 open, picture 2 closed).

 

image.thumb.png.4e531361356ba9dfe867cd03e1353f4a.png

Picture 1.

 

image.thumb.png.e0d8712fb4e7a95fb95f64ef80acc19e.png

Picture 2.

 

50 minutes ago, DATVO said:

If it’s just a line, the "geometric center” is the midpoint. 

 

This is true.

 

Best regards.

  • Like 1
  • Thanks 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...