Jump to content

LISP Use the Arx-AcGe Geometry library to find the overlap of two polylines


Recommended Posts

Posted

Video_2024-04-18_215104.gif.30d149e46b23e7cb145d167469285660.gif

 

 

==================

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.

 

20140714211443234(2).gif.8a7b3bd322168539d9284cd7fda06d07.gif


==============

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

===============

 

(defun XD::Curve:GetSub (e p1 p2 testPnt / ge1 pa1 pa2 testpa)
  (defun _isclose ()
    (and
      ;(xdrx_getpropertyvalue e "isclosed")
      (or
        (>= pa1 testpa)
        (<= pa2 testpa)
      )
    )
    (not (< pa1 testpnt pa2))
  )
  (defun _trimEnts (ge1 pa1 pa2)
    (xdge::setpropertyvalue ge1 "setinterval" pa1 pa2)
    ge1
  )
  (setq ge1 (xdge::constructor e))
  (if (= (type p1) 'LIST)
    (progn
      (setq p1 (trans p1 1 0)
            p2 (trans p2 1 0)
      )
      (if (not testpnt)
        (setq testpnt '(0 0 0))
        (setq testPnt (trans testpnt 1 0))
      )
      (setq pa1 (xdge::getpropertyvalue ge1 "paramof" p1)
            pa2 (xdge::getpropertyvalue ge1 "paramof" p2)
            testPa (xdge::getpropertyvalue ge1 "paramof" testPnt)
      )
    )
    (progn
      (setq pa1 p1
            pa2 p2
      )
      (if (not testpnt)
        (setq testpa 0.0)
        (setq testpa testpnt)
      )
    )
  )
  (mapcar
    'set
    '(pa1 pa2)
    (vl-sort (list pa1 pa2) '<)
  )
  (if (_isclose)
    (setq ge1 (_trimEnts ge1 pa2 pa1))
    (setq ge1 (_trimEnts ge1 pa1 pa2))
  )
  ge1
)
 

 

(defun c:tt ()
   (if (and (setq e1 (car (xdrx_entsel
                            "\nSelect the first polyline<Exit>:"
                            '((0 . "LWPOLYLINE"))
                          )
                     )
            )
            (setq e2 (car (xdrx_entsel
                            "\nSelect second polyline <Exit>:"
                            '((0 . "LWPOLYLINE"))
                          )
                     )
            )
       )
     (progn
       (setq g1 (xdge::constructor e1) ;;Construct the geometric entity of the first polyline
             g2 (xdge::constructor e2) ;;Construct the geometric entity of the second polyline
       )
       (if (setq gint (xdge::constructor "kCurveCurveInt3d" g1 g2)) ;;Construct AcGeCurveCurveInt3d object from two geometric entities
         (progn
           (setq num (xdge::getpropertyvalue gint "overlapcount")) ;;Get the number of overlapping segments
           (setq i -1
                 ss (ssadd)
           )
           (repeat num
             (setq i (1+ i)
                   g (xdge::getpropertyvalue gint "getOverLapRanges" i) ;;Get the overlapping curve range parameters of the i-th segment
                   intv1 (car g) ;;Get the range AcGeInterval object of the overlapping part of the first curve
                   param (xdge::getpropertyvalue intv1 "getbounds") ;;Get the upper and lower range of curve parameters from AcGeInterval
             )
             (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)
             (xdge::entity:make e) ;;Generate database AcDbPolyline object
             (xdrx_setpropertyvalue;;Set color 6, constant width 60
               (entlast)
               "color"
               6
               "constantwidth"
               60.0
             )
             (ssadd (entlast) ss)
           )
           (xdrx_prompt "\n" num "Overlapping segments found, marked in magenta.")
           (sssetfirst nil ss)
         )
       ) (xdge::free)
     )
   )
   (princ)
)

 

=================

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)
"AcGe::kLineSeg3d"

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

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

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)
"AcGe::kCurveCurveInt3d"

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

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))
"AcGeInterval"

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
"kLineSeg3d"

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)
"AcDbLine"

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)

<kCurveCurveInt3d>:


    Edit Functions:
         ├───set


    Intersection Query Functions:
         ├───intPoint
         ├───intPoints
         ├───intPointTol
         ├───isTangential
         ├───isTransversal
         ├───numIntPoints
         ├───overlapCount
         ├───overlapDirection


    Ordering Functions:
         ├───changeCurveOrder
         ├───orderWrt1
         ├───orderWrt12


    Query Functions:
         ├───curve1
         ├───curve2
         ├───getIntParams
         ├───getIntRanges
         ├───getOverlapRanges
         ├───getPointOnCurve1
         ├───getPointOnCurve2
         ├───tolerance




<kEntity3d>:


    Equality Checking Functions:
         ├───isEqualTo


    Point Containment Functions:
         ├───isOn


    Type Identification Functions:
         ├───isKindOf
         ├───type

=======================

The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API

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

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