Author Topic: [AcGe(1)]Explore how to obtain the overlapping portion of two curves  (Read 297 times)

0 Members and 1 Guest are viewing this topic.


  • Newt
  • Posts: 194


The AcGe class library is a tool class library provided for the AcDb class library, such as vector objects and matrix objects for two-dimensional and three-dimensional operations. In addition, many basic geometric objects are provided, such as points, curves, and surfaces.

The AcGe class library mainly contains two sub-sets: classes for two-dimensional calculations and classes for three-dimensional calculations. The main base classes are AcGeEntity2d and AcGeEntity3d. There are also several classes without a base class, including AcGePoint2d, AcGeVector2d, and AcGeMaterix2d. These basic classes can be used to perform many types of common operations, such as point and vector operations, multiplication and cross-multiplication between vectors. Operations between matrices. Many implementations of these subclasses make use of the operations of these base classes.


Let’s discuss how to get the overlapping part of two curves

There is a class AcGeCurveCurveInt3d in the geometry library. This class handles various positional relationships between two intersecting curves. Among them
1. The overlapCount method obtains the number of overlapping segments.
2. getOverLapRanges obtains the parameter (AcGeInterval) of the overlapping range on the two curves at the specified index (number, based on 0)

After getting the overlapping parameter range, you can deduct the local curve (using the xd::curve:getsub function of the general function library)

XDRX API encapsulates ARX's geometry library methods for LISP calls

Code - Auto/Visual Lisp: [Select]
  1. (defun XD::Curve:GetSub (e p1 p2 testPnt / ge1 pa1 pa2 testpa)
  2.   (defun _isclose ()
  3.     (and
  4.       ;(xdrx_getpropertyvalue e "isclosed")
  5.       (or
  6.         (>= pa1 testpa)
  7.         (<= pa2 testpa)
  8.       )
  9.     )
  10.     (not (< pa1 testpnt pa2))
  11.   )
  12.   (defun _trimEnts (ge1 pa1 pa2)
  13.     (xdge::setpropertyvalue ge1 "setinterval" pa1 pa2)
  14.     ge1
  15.   )
  16.   (setq ge1 (xdge::constructor e))
  17.   (if (= (type p1) 'LIST)
  18.     (progn
  19.       (setq p1 (trans p1 1 0)
  20.             p2 (trans p2 1 0)
  21.       )
  22.       (if (not testpnt)
  23.         (setq testpnt '(0 0 0))
  24.         (setq testPnt (trans testpnt 1 0))
  25.       )
  26.       (setq pa1 (xdge::getpropertyvalue ge1 "paramof" p1)
  27.             pa2 (xdge::getpropertyvalue ge1 "paramof" p2)
  28.             testPa (xdge::getpropertyvalue ge1 "paramof" testPnt)
  29.       )
  30.     )
  31.     (progn
  32.       (setq pa1 p1
  33.             pa2 p2
  34.       )
  35.       (if (not testpnt)
  36.         (setq testpa 0.0)
  37.         (setq testpa testpnt)
  38.       )
  39.     )
  40.   )
  41.   (mapcar
  42.     'set
  43.     '(pa1 pa2)
  44.     (vl-sort (list pa1 pa2) '<)
  45.   )
  46.   (if (_isclose)
  47.     (setq ge1 (_trimEnts ge1 pa2 pa1))
  48.     (setq ge1 (_trimEnts ge1 pa1 pa2))
  49.   )
  50.   ge1
  51. )

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (if (and (setq e1 (car (xdrx_entsel
  3.                             "\nSelect the first polyline<Exit>:"
  4.                             '((0 . "LWPOLYLINE"))
  5.                           )
  6.                      )
  7.             )
  8.             (setq e2 (car (xdrx_entsel
  9.                             "\nSelect second polyline <Exit>:"
  10.                             '((0 . "LWPOLYLINE"))
  11.                           )
  12.                      )
  13.             )
  14.        )
  15.      (progn
  16.        (setq g1 (xdge::constructor e1) ;;Construct the geometric entity of the first polyline
  17.              g2 (xdge::constructor e2) ;;Construct the geometric entity of the second polyline
  18.        )
  19.        (if (setq gint (xdge::constructor "kCurveCurveInt3d" g1 g2)) ;;Construct AcGeCurveCurveInt3d object from two geometric entities
  20.          (progn
  21.            (setq num (xdge::getpropertyvalue gint "overlapcount")) ;;Get the number of overlapping segments
  22.            (setq i -1
  23.                  ss (ssadd)
  24.            )
  25.            (repeat num
  26.              (setq i (1+ i)
  27.                    g (xdge::getpropertyvalue gint "getOverLapRanges" i) ;;Get the overlapping curve range parameters of the i-th segment
  28.                    intv1 (car g) ;;Get the range AcGeInterval object of the overlapping part of the first curve
  29.                    param (xdge::getpropertyvalue intv1 "getbounds") ;;Get the upper and lower range of curve parameters from AcGeInterval
  30.              )
  31.              (setq e (xd::curve:getsub e1 (car param) (cadr param) 0)) ;;Call the general LISP function library function to deduct part of the curve entity (geometric entity)
  32.              (xdge::entity:make e) ;;Generate database AcDbPolyline object
  33.              (xdrx_setpropertyvalue;;Set color 6, constant width 60
  34.                (entlast)
  35.                "color"
  36.                6
  37.                "constantwidth"
  38.                60.0
  39.              )
  40.              (ssadd (entlast) ss)
  41.            )
  42.            (xdrx_prompt "\n" num "Overlapping segments found, marked in magenta.")
  43.            (sssetfirst nil ss)
  44.          )
  45.        ) (xdge::free)
  46.      )
  47.    )
  48.    (princ)
  49. )


AcGeCurveCurveInt3d class, XDRXAPI encapsulated method

Typical process of generating overlapping segments:

1.Construct the AcGe geometric object corresponding to curve 1.

Command:(setq g1 (xdge::constructor (entlast)))
<图元名: 2a1fcf01610>

Command: (xdrx-object-isa g1)

2.Construct the AcGe geometric object corresponding to curve 2.

Command:(setq g2 (xdge::constructor (entlast)))
<图元名: 2aa0895d400>
Command: (xdrx-object-isa g2)

3.Construct the AcGe geometric object corresponding to kCurveCurveInt3d where curve 1 and curve 2 intersect.

Command: (setq gint (xdge::constructor "kCurveCurveInt3d" g1 g2))
<图元名: 2aa0895d8c0>

Command: (xdrx-object-isa gint)

4.Get the number of overlapping segments.
Command: (setq num (xdge::getpropertyvalue gint "overlapcount"))

5.Get the overlapping curve range parameters of the i-th segment

Command: (setq g (xdge::getpropertyvalue gint "getOverLapRanges" 0))
(<图元名: 2aa0895cd20> <图元名: 2aa0895cf20>)

Command:(xdge::type (car g))

6.Get the upper and lower range of curve parameters from AcGeInterval

Command: (xdge::getpropertyvalue (car g) "getbounds")
(0.5 1.0)

7.;The setintval method obtains the kLine3d geometric curve

Command: (setq gint (xdge::setpropertyvalue g1 "setinterval" (car param)(cadr param)))
<图元名: 2a1fcf01610>

Command:(xdge::type gint); AcGe::KLineSeg3d Object

8.;Generate the database AcDbLine object and obtain the curve entity of the overlapping segment.

Command:(setq e (xdge::entity:make gint))
<图元名: 2a1d36c5dd0>

命令: (xdrx-object-isa e)

If only the entity name is given as a parameter, the query and editing C++ methods that support this geometric object will be printed.

Command: (xdge::getpropertyvalue gint)


    Edit Functions:

    Intersection Query Functions:

    Ordering Functions:

    Query Functions:


    Equality Checking Functions:

    Point Containment Functions:

    Type Identification Functions:


The above LISP code uses the XDRX-API, which can be downloaded from

The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.

« Last Edit: November 16, 2023, 11:14:50 PM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from and is updated at any time.
[XDrx-Sub Forum]