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

0 Members and 1 Guest are viewing this topic.

• Swamp Rat
• Posts: 527
##### [AcGe(1)]Explore how to obtain the overlapping portion of two curves
« on: November 16, 2023, 10:25:53 PM »

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

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.       (setq p1 (trans p1 1 0)
19.             p2 (trans p2 1 0)
20.       )
21.       (if (not testpnt)
22.         (setq testpnt '(0 0 0))
23.         (setq testPnt (trans testpnt 1 0))
24.       )
25.       (setq pa1 (xdge::getpropertyvalue ge1 "paramof" p1)
26.             pa2 (xdge::getpropertyvalue ge1 "paramof" p2)
27.             testPa (xdge::getpropertyvalue ge1 "paramof" testPnt)
28.       )
29.     )
30.       (setq pa1 p1
31.             pa2 p2
32.       )
33.       (if (not testpnt)
34.         (setq testpa 0.0)
35.         (setq testpa testpnt)
36.       )
37.     )
38.   )
39.     'set
40.     '(pa1 pa2)
41.     (vl-sort (list pa1 pa2) '<)
42.   )
43.   (if (_isclose)
44.     (setq ge1 (_trimEnts ge1 pa2 pa1))
45.     (setq ge1 (_trimEnts ge1 pa1 pa2))
46.   )
47.   ge1
48. )
49.

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.        (setq g1 (xdge::constructor e1) ;;Construct the geometric entity of the first polyline
16.              g2 (xdge::constructor e2) ;;Construct the geometric entity of the second polyline
17.        )
18.        (if (setq gint (xdge::constructor "kCurveCurveInt3d" g1 g2)) ;;Construct AcGeCurveCurveInt3d object from two geometric entities
19.            (setq num (xdge::getpropertyvalue gint "overlapcount")) ;;Get the number of overlapping segments
20.            (setq i -1
22.            )
23.            (repeat num
24.              (setq i (1+ i)
25.                    g (xdge::getpropertyvalue gint "getOverLapRanges" i) ;;Get the overlapping curve range parameters of the i-th segment
26.                    intv1 (car g) ;;Get the range AcGeInterval object of the overlapping part of the first curve
27.                    param (xdge::getpropertyvalue intv1 "getbounds") ;;Get the upper and lower range of curve parameters from AcGeInterval
28.              )
29.              (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)
30.              (xdge::entity:make e) ;;Generate database AcDbPolyline object
31.              (xdrx_setpropertyvalue;;Set color 6, constant width 60
32.                (entlast)
33.                "color"
34.                6
35.                "constantwidth"
36.                60.0
37.              )
39.            )
40.            (xdrx_prompt "\n" num "Overlapping segments found, marked in magenta.")
41.            (sssetfirst nil ss)
42.          )
43.        ) (xdge::free)
44.      )
45.    )
46.    (princ)
47. )

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

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>

"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

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