Jump to content

Recommended Posts

Posted

How can we create a vertex at the clicked point by selecting one of the sides of a polygon and modify the area of the polygon using the triangle area formula?
The created vertex must be moved inwards or outwards by (2*polygon area/clicked side length) to modify the area of the polygon.

It is important that the coordinates of the vertices and the length of the other sides of the polygon do not change

Screenshot 2024-01-17 123335.jpg

Posted

Might need a few more details:

is it always the edge defined be lowest right - upper right corners that is modified regardless of any rotation? Or will the user pick the edge

Will it always be a rectangle defined by 4 points in the line or could there be more points in the polyline?

I'd assume you will need user input to get the desired new size, it won't be fixed at 2000m2?

 

The calculation is quite easy, the 'point' moves, (Point Distance) = (increase in area) / (0.5 * Rectangle 'Length')

There are LISPs out there to add a vertex to a polyline

 

So all you need to do is work out the corners and then where to add the new point, 

 

 

I'll have a play with this later today

Posted (edited)

No, the polygon may be 6-sided or more
For a simple example, I drew a rectangle
I select the desired side by clicking because every time one of the sides may not have an important length and the modification must be done on it.
For example, I wrote the area as 2000. Any shape may have a different area, and I will introduce the correct area to it.

 

Thank you very much for your efforts

Screenshot 2024-01-17 133941.jpg

Edited by ehsantavassolian
Posted (edited)

I got most of the code. 

 

command MPA for: Modification of Polygon Area

- Select the polyline.  The point on the polyline on which the user clicks is where the vertex is added.

- Then enter the area you want.

 

Just one unfinished thing: checking if the vertex should be pulled to the left or the right (to the inside or outside of the polyline).

Anyway, I draw a little line.  Pull the vertex to the other side of the little line when needed.

 

Anyone feel free to fill in that last one.  I got to go now.

 

 


(vl-load-com) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; LW Vertices  -  Lee Mac
;; Returns a list of lists in which each sublist describes
;; the position, starting width, ending width and bulge of the
;; vertex of a supplied LWPolyline
(defun LM:LWVertices ( e )
    (if (setq e (member (assoc 10 e) e))
        (cons
            (list
                (assoc 10 e)
                (assoc 40 e)
                (assoc 41 e)
                (assoc 42 e)
            )
            (LM:LWVertices (cdr e))
        )
    )
)

;; Tangent  -  Lee Mac
;; Args: x - real
(defun tan ( x )
    (if (not (equal 0.0 (cos x) 1e-10))
        (/ (sin x) (cos x))
    )
)

;; Heavily inspired (I hope that's okay) by
;; http://www.lee-mac.com/addpolyvertex.html
;; I took the user input out of the function, they're now parameters of the function. 
;; Nor does it error check much.
;;
(defun addVertexToLWPolyline ( e p on_pline / a b e h l n p r v w x z p_orig)
    (if (and p e
            (setq 
				p_orig p
				p (vlax-curve-getclosestpointto e (trans p 1 0))
				n (vlax-curve-getparamatpoint e p)
            )
        )
        (if (not (equal n (fix n) 1e-8))
            (progn
                (setq e (entget e)
                      h (reverse (member (assoc 39 e) (reverse e)))
                      v (assoc 90 h)
                      l (LM:LWVertices e)
                      z (assoc 210 e)
                )
                (repeat (fix n)
                    (setq a (cons (car l) a)
                          l (cdr l)
                    )
                )
                (setq x (car l)
                      r (- n (fix n))
                      w (cdr (assoc 40 x))
                      w (+ w (* r (- (cdr (assoc 41 x)) w)))
                      b (atan (cdr (assoc 42 x)))
                )
				
				;; if on_pline is nil, then we keep the opiginal point given by the user
				(if on_pline
					T
					(setq p p_orig)
				)
				
                ;;(LM:startundo (LM:acdoc))
                (entmod
                    (append
                        (subst (cons 90 (1+ (cdr v))) v h)
                        (apply 'append (reverse a))
                        (list
                            (assoc 10 x)
                            (assoc 40 x)
                            (cons  41 w)
                            (cons  42 (tan (* r b)))
                            (cons  10 (trans p 0 (cdr z)))
                            (cons  40 w)
                            (assoc 41 x)
                            (cons  42 (tan (* (- 1.0 r) b)))
                        )
                        (apply 'append (cdr l))
                        (list z)
                    )
                )
                ;;(LM:endundo (LM:acdoc))
            )
        )
    )
	e	;; return the modified polyline
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://www.lee-mac.com/round.html
;; Round Up  -  Lee Mac
;; Rounds 'n' up to the nearest 'm'
(defun LM:roundup ( n m )
    ((lambda ( r ) (cond ((equal 0.0 r 1e-8) n) ((< n 0) (- n r)) ((+ n (- m r))))) (rem n m))
)

;; Round Down  -  Lee Mac
;; Rounds 'n' down to the nearest 'm'
(defun LM:rounddown ( n m )
    ((lambda ( r ) (cond ((equal 0.0 r 1e-8) n) ((< n 0) (- n r m)) ((- n r)))) (rem n m))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun drawLine (p1 p2)
 (entmakex (list (cons 0 "LINE")
                 (cons 10 p1)
                 (cons 11 p2)))
)

;; command MPA for: Modification of Polygon Area
(defun c:mpa ( / sel pt rect area area_tobe area_diff par start_ end_ ptl ptr polar_dist)
	(setq sel (entsel "\nSelect rectangle. The clicked : "))
	(setq rect (car sel))
	(setq pt (cadr sel))
	(setq pt (vlax-curve-getClosestPointTo (vlax-ename->vla-object rect) pt))
	
	(princ "\npt: ")
	(princ pt)
	(princ "\nArea: ")
	
	(setq b (vlax-ename->vla-object rect))
	(princ (rtos (setq area (vla-get-area b)) 2 5))
	
	(setq area_tobe (getreal "\nWhat area should it be: "))
	(princ "\nArea of the triangle: ")
	(setq area_diff (- area_tobe area))
	(princ area_diff)
	
			;; parameter -> this tells you the index of the segment.  And where on the segment the point is
			(setq par (vlax-curve-getparamatpoint (vlax-ename->vla-object rect) pt))  ;; (vlax-ename->vla-object pl)
			;; start point of the segment 
			(setq start_ (vlax-curve-getPointAtParam (vlax-ename->vla-object rect) (LM:rounddown par 1.0)))
			(setq end_   (vlax-curve-getPointAtParam (vlax-ename->vla-object rect) (LM:roundup par 1.0)))
		
	(princ "\nPolar distance to 3rd point of the triangle: ")
	(setq polar_dist (/ (* area_diff 2.0) (distance start_ end_ ) ))
		
		;; now we make a triangle: start_ end_ pt2 (pt2 will be either ptl or ptr, see later)
		;; the area of the triangle = (distance start_ end_ ) X (distance pt2 (line start_ end_ )) / 2 
		
			;; now we need a point perpendicular to line start_ end_ on point pt.
			;; it may be to the left or to the right.
				;; (polar pt ang dist)
				;; left:
	(setq ptl (polar pt (+ (angle start_ end_)   (/ pi 2.0)) polar_dist) )
	(setq ptr (polar pt (- (angle start_ end_)   (/ pi 2.0)) polar_dist) )
			
	(addVertexToLWPolyline rect ptl nil)

	(drawLine  ptl ptr)
	(princ)
)

 

Edited by Emmanuel Delay
Posted

that was perfect
thanks a lot
It worked properly and is what I wanted

👏

  • Like 1
  • 2 months later...
Posted
On 1/17/2024 at 5:14 PM, ehsantavassolian said:

How can we create a vertex at the clicked point by selecting one of the sides of a polygon and modify the area of the polygon using the triangle area formula?
The created vertex must be moved inwards or outwards by (2*polygon area/clicked side length) to modify the area of the polygon.

It is important that the coordinates of the vertices and the length of the other sides of the polygon do not change

Screenshot 2024-01-17 123335.jpg

 

 

[XDrX-PlugIn(125)] Modify the polyline according to the specified area. (theswamp.org)

https://www.theswamp.org/index.php?topic=59426.0

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...