Programming by Dragging Grips (1)
https://www.theswamp.org/index.php?topic=58841.msg617609#msg617609Last time I talked about simulating user operations and editing pinch points to complete the operation. Please see the above post for the specific process.
Now we are simulating one more time, the simulation process of fitting the rectangular polyline and the circle boundary
The process that the user wants to do:
Drag the polyline clamp to the circle, and then use BPOLY, TRIM or other commands to complete the operation. In fact, it is to find the "Subtract" between the polyline and the circle topology after stretching. We will complete one more difference operation than last time.
==========
If you don’t use simulation and just write code, you need:
1. Calculate the two nearest intersection points of the two straight segments of the polyline and the circle
2. The part of the circle between these two points is the final Overlap. Use the SetIterval of the geometry library to extract the overlapping arc.
3. Reconstruct the polyline using arcs and extended rectangles
It is more complicated than directly simulating the STRETCH, BPOLY, and TRIM commands.
(setq dest
(car (xdrx
-entsel "\nPick Dest Curve<Exit>:" '
((0 .
"circle"))))) (setq src
(xdrx
-entsel "\nPick Extend PolySeg<Exit>:" '
((0 .
"*polyline")))) )
(setq seg
(xdrx
-getpropertyvalue src
"onsegat" pt
)) (setq nextInx
(xdrx
-getpropertyvalue src
"-index+" inx
)) )
(setq p0
(xdrx
-getpropertyvalue src
"pointat" previnx
) p1 (xdrx-getpropertyvalue src "pointat" inx)
p2 (xdrx-getpropertyvalue src "pointat" nextInx)
p3 (xdrx-getpropertyvalue src "pointat" nextinx+)
)
(setq int1
(xdrx
-entity
-intersectwith
(list p0 p1
) dest
3)) (setq int2
(xdrx
-entity
-intersectwith
(list p2 p3
) dest
3)) )
(xdrx_entity_movestretchpoint src
(mapcar '
- (car int1
) p1
) inx
) (xdrx_entity_movestretchpoint src
(mapcar '
- (car int2
) p2
) nextInx
) (setq dest
-copy
(xdrx
-object
-clone dest
)) (xdrx-get-subtract src dest-copy)
)
)
)