(defun eea-centroid-curve-lw (pl bl / L) ;|*****************************************************************************************by ElpanovEvgeniy*****************************************************************************************Library function.The center of the weight located along a contour of a lwpolyline, having arc segments.As an example, the center of weight of a wire detail!!! For the closed polylines to add the description of a closing segment.pl - list pointbl - list bulgeDate of creation 2000 - 2005 years.Last edit 08.06.2009*****************************************************************************************(setq e (car (entsel "\n Select LWPOLYLINE ")) pl nil bl nil) ;_ setq(foreach a (reverse (entget e))(cond ((= (car a) 10) (setq pl (cons (cdr a) pl))) ((= (car a) 42) (setq bl (cons (cdr a) bl)))) ;_ cond) ;_ foreach(eea-centroid-curve-lw pl bl)*****************************************************************************************(defun c:c2 (/ e bl pl)(setq e (car (entsel)))(foreach a (reverse (entget e)) (cond ((= (car a) 10) (setq pl (cons (cdr a) pl))) ((= (car a) 42) (setq bl (cons (cdr a) bl))) ) ;_ cond) ;_ foreach(if (= (cdr (assoc 70 (entget e))) 1) (setq pl (reverse (cons (car pl) (reverse pl))))) ;_ if(entmakex (list '(0 . "point") '(62 . 2) (cons 10 (eea-centroid-curve-lw pl bl)) (assoc 210 (entget e)) ) ;_ list) ;_ entmakex) ;_ defun*****************************************************************************************|;(setq l 0)(mapcar (Function /) (apply (function mapcar) (cons (function +) (mapcar (function (lambda (p1 p2 b / BB C D S) (if (zerop b) (progn (setq d (distance p1 p2) l (+ d l) ) ;_ setq (mapcar (function (lambda (a b c) (* (/ (+ a b) 2) c))) p1 p2 (list d d)) ) ;_ progn (progn (setq c (distance p1 p2) bb (* b b) d (/ (* c (atan b) (1+ bb)) b) l (+ d l) s (- (/ 1 (* 4 (atan b))) (/ (- 1 bb) (* 4 b))) ) ;_ setq (mapcar (function (lambda (a b c) (* d (+ (/ (+ a b) 2) c)))) p1 p2 (list (* s (- (cadr p2) (cadr p1))) (* s (- (car p1) (car p2)))) ) ;_ mapcar ) ;_ progn ) ;_ if ) ;_ lambda ) ;_ function pl (cdr pl) bl ) ;_ mapcar ) ;_ cons ) ;_ apply (list l l)) ;_ mapcar) ;_ defun
Hi, this lisp calculate center of weight for the closed polylines but I have a problem if it is applied a piercing operation on the material how do I calculate the center of weight. I need a lisp (only geometry not region).
I do not want to calculate centroid I want to calculate center of pressure. That is, they are different things. Center of pressure the center of gravity of the perimeter of blank (not the area blank). The above lisp calculates it but How do I calculate that when there is a hole on the figure.
For a 2D object, centroid is the correct term for whatever shape you have. Have you looked at using REGION, SUBTRACT & MASSPROP? There is probably a LISP routine floating around that would plot the resultant X-Y point of the centroid, but you can do it manually using cut & paste.
You can specify center of each polyline, let denote them C1 and C2. The mass of each polyline is proportional to the length, let say L1 and L2. Then the center of the 2 would lay in the middle of C1 and C2, where L1 and L2 get balance.
there is an example for manual calculation. When there is a hole on the figure I need to subtract the length of the perimeter of the hole. Then center of gravity will change. I wonder how a lisp can be written.