intersections between 3dpoly

intersections between 3dpoly

Anonymous
Not applicable
2,571 Views
8 Replies
Message 1 of 9

intersections between 3dpoly

Anonymous
Not applicable

Hello all,

 

I have multiple intersections between 3dpoly ...
For which "intersectwith" method can not be applied.

 

What I intend to do is add a vertex to each of the 3dpoly at the intersection between them, with Z being the average of the apparent intersections elevations. (Goal 1)
... If it is possible, the tolerance between elevations will eventually be requested and the intersections that have exceeded tolerance will be marked. (Goal 1+)

I am aware of the fact that it's complex work.

 

... I think I would be content with trimming the intersection area locally (Goal 2)

 

Thanks in advance,

AoS

0 Likes
Accepted solutions (1)
2,572 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

Goal 2 is pretty simple to do manually.  Draw a Circle of the intended size anywhere.  Set APParent-Intersection as the one running Object-Snap mode.  Select the Circle, grab its midpoint grip, and go into Copy mode, and plonk it at all the apparent intersections.  Trim using the Circles as cutting edges.  Erase the Circles [which will be the Previous selection].

 

I did it in your sample drawing, and it took about a minute and a half.  You could do a lot of those in the time it would take to come up with a routine to automate Goal 1.

Kent Cooper, AIA
0 Likes
Message 3 of 9

Anonymous
Not applicable

@Kent1Cooper wrote:

Goal 2 is pretty simple to do manually.

 

Thank you, Mr. Cooper

 

That's what I did in the attached example.
Please imagine hundreds of such intersections in many kilometers of topographical survey.

 

Best regards,

AoS

0 Likes
Message 4 of 9

john.uhden
Mentor
Mentor

Are you looking for their point of apparent intersection as you would look at them in plan view, or do you know that they really have a 3D point of intersection?

If it is the former, then you could temporarily flatten them to get the intersection point(s).  Then you could get the intersection parameters, unflatten them, and get the points at the params.

John F. Uhden

0 Likes
Message 5 of 9

Anonymous
Not applicable

Hello John,

 

I have specified in my first post that the "intersectwith" method does not work. So is a veritable 3D intersection.


I can form a list with the x and y coordinates of the plane intersection point using the function LM:intersections (Thanks Lee Mac!).
I do not know how to get the two levels of this intersection.
I want to introduce in the list of x and y the Z obtained as average of the two levels, and then to use this new list to introduce vertexes on both 3dpoly.

 

Best regards,

AoS

0 Likes
Message 6 of 9

john.uhden
Mentor
Mentor
I was trying to explain that if you temporarily flatten the 3D polys into
2D polys (at the same elevation), then you can use intersectwith to find
the 2D coordinates and the get the paramatpoint for each. For polylines,
parameters increase by 1 for each vertex so that a param of 0.5 is
literally hallway between the 1st and 2nd vertices, no matter whether the
polyline is 2D or 3D.
Then you can get each 3D point by using getpointatparam.
You don't have to use the FLATTEN command. Instead you can (setq coords
(vlax-get object 'Coordinates)), change all their Z values to zero (I can
show you how if you need), (vlax-put object 'Coordinates zeros) for each
and then vla-intersectwith. After that (vlax-put object 'Coordinates
coords) to return them to 3D.

Just be careful because getcoordinates returns a flat list (x1 y1 z1 x2 y2
z2 xn yn zn) and they must be put back as a flat list, but I can show you
how if you need.

John F. Uhden

Message 7 of 9

Kent1Cooper
Consultant
Consultant

@aosrom wrote:

....
I do not know how to get the two levels of this intersection.
I want to introduce in the list of x and y the Z obtained as average of the two levels....


Once you get the XY apparent intersections somehow, you can use the (vlax-curve-getClosestPointToProjection) function [read about it] to find where that falls on each Polyline.  You might find it helpful to Search for examples of its usage in this Forum.

Kent Cooper, AIA
Message 8 of 9

trevor.bird.au
Advocate
Advocate
Accepted solution

Hi Adrian,

 

The code below will add the intersection vertex to each 3D polyline; I've only tested it on the drawing you provided.

 

It uses the method John Uhden described:

  1. Determine the intersection points using flattened copies of the selected 3D polylines i.e. Z = 0.0.
  2. Get the parameter (ParmAtPoint) at the intersection point of the flattened polylines.
  3. Use the parameter to get the 3D intersection point on each 3D polyline.
  4. Add the 3D intersection point to the coordinates of the 3D polyline.

I've processed the intersections of the flattened 3D polylines inside a block definition.

I use a block definition as a "sandbox" where modifications are made to copies of the existing selected 3D polylines leaving the originals unchanged.

Also if an error occurs, the original 3D polylines remain unchanged and any modified geometry only exists in the block definition which can be purged.

 

The modified 3D polylines are grip selected which shows a grip at all the vertices.

 

Regards,

Trevor

;;  3DPolyInters.lsp by Trevor Bird
;;
;;  2018-01-25

;;------------------------------------------------------------------------------
(defun c:3dpolyinters
  (
    /

    Block_Name

    color_int
    col_Block
    col_Blocks
    Coordinates1_list
    Coordinates1_sa
    Coordinates1_var
    Coordinates2_list
    Coordinates2_sa
    Coordinates2_var
    Coordinates3_list
    Coordinates3_sa
    Coordinates3_var
    Coordinates4_list
    Coordinates4_sa
    Coordinates4_var

    dps_Params1
    dps_Params2

    EndParam1
    EndParam2

    flag_Intersects

    Inters1_list
    Inters1_Point
    Inters1_sa
    Inters1_var

    list_params1
    list_params2

    Objects1_sa
    Objects2_list
    Objects2_var
    obj_AD
    obj_POLYLINE1
    obj_POLYLINE1:2D
    obj_POLYLINE1:3D
    obj_POLYLINE2
    obj_POLYLINE2:2D
    obj_POLYLINE2:3D

    Param1
    Param2
    ParamAtPoint1
    ParamAtPoint2
    PointAtParam1:3D
    PointAtParam1_list
    PointAtParam2:3D
    PointAtParam2_list
    POLYLINE1_ename
    POLYLINE2_ename

    ssC1
    ssC2
    ss_Filter
    ss_length1
    ss_length2
    ss_modified
    ss_POLYLINES
    StartParam1
    StartParam2
    sv_cvport
  )
  (setq obj_AD      (vlax-get-property (vlax-get-acad-object) 'ActiveDocument)
        col_Blocks  (vlax-get-property obj_AD 'Blocks)

        sv_cvport   (getvar 'CVPORT)
  );setq

  (setq ss_Filter
    '(
      (0 . "POLYLINE")
      (-4 . "&=")
      (70 . 8)
    );'
  );setq

  (if (= sv_cvport 1)
    (setq ss_Filter  (append ss_Filter (list (cons 410 (getvar 'CTAB)))))
    (setq ss_Filter  (append ss_Filter '((410 . "Model"))))
  );if (= sv_cvport 1)




  (setq ss_POLYLINES  (ssget ":L" ss_Filter))

  (cond
    ( (not ss_POLYLINES)
      (princ "\nNo Polylines selected.")
    );(not ss_POLYLINES)


    (ss_POLYLINES
      ;;  <!--
      ;;  Do intersection processing inside a block definition so that construction geometry can be easily managed and deleted.
      (setq Block_Name  "3DPolyInters_DELETE_ME")

      (cond
        ( (not (tblsearch "BLOCK" Block_Name))
          (setq col_Block  (vlax-invoke-method col_Blocks 'Add (vlax-3D-point '(0.0 0.0 0.0)) Block_Name))

          (vlax-put-property col_Block 'BlockScaling acUniform)
          (vlax-put-property col_Block 'Explodable :vlax-true)
          (vlax-put-property col_Block 'Units (getvar 'InsUnits))
        )

        (T
          (setq col_Block  (vlax-invoke-method col_Blocks 'Item Block_Name))

          (vlax-for vf::objectcb col_Block
            (vlax-invoke-method vf::objectcb 'Delete)
          );vf::objectcb
        );T
      );cond
      ;;  -->


      (setq ssC1         -1
            ss_length1   (sslength ss_POLYLINES)
            color_int    0
            ss_modified  (ssadd)
      );setq

      (repeat ss_length1
        (setq POLYLINE1_ename    (ssname ss_POLYLINES (setq ssC1  (1+ ssC1)))
              obj_POLYLINE1      (vlax-ename->vla-object POLYLINE1_ename)

              color_int          (1+ color_int)

              StartParam1        (vlax-curve-getStartParam obj_POLYLINE1)
              EndParam1          (vlax-curve-getEndParam obj_POLYLINE1)
              Param1             StartParam1
              dps_Params1        nil
              Coordinates1_list  nil
        );setq

        (repeat (1+ (fix EndParam1))
          (setq PointAtParam1_list  (vlax-curve-getPointAtParam obj_POLYLINE1 Param1)
                dps_Params1         (append dps_Params1 (list (cons Param1 PointAtParam1_list)))
                Coordinates1_list   (append Coordinates1_list (list (car PointAtParam1_list) (cadr PointAtParam1_list) 0.0))
                Param1              (+ Param1 1.0)
          );setq
        );repeat (1+ (fix EndParam1))


        ;;  <!-- Copy obj_POLYLINE1 into block created for intersection processing geometry.
        (setq Objects1_sa  (vlax-make-safearray vlax-vbObject '(0 . 0)))

        (vlax-safearray-fill Objects1_sa (list obj_POLYLINE1))

        (setq Objects2_var      (vlax-invoke-method obj_AD 'CopyObjects Objects1_sa col_Block)
              Objects2_list     (vlax-safearray->list (vlax-variant-value Objects2_var))
              obj_POLYLINE1:2D  (car Objects2_list)
              obj_POLYLINE1:3D  (vlax-invoke-method obj_POLYLINE1:2D 'Copy)
        );setq


        ;;  Flatten obj_POLYLINE1:2D i.e. Z = 0.0
        (setq Coordinates1_sa  (vlax-make-safearray vlax-vbDouble (cons 0 (1- (length Coordinates1_list)))))

        (vlax-safearray-fill Coordinates1_sa Coordinates1_list)

        (setq Coordinates1_var  (vlax-make-variant Coordinates1_sa (logior vlax-vbArray vlax-vbDouble)))

        (vlax-put-property obj_POLYLINE1:2D 'Coordinates Coordinates1_var)
        (vlax-invoke-method obj_POLYLINE1:2D 'Update)
        ;;  -->


        ;;  <!-- Check for intersections with obj_POLYLINE1 and the rest of the 3D polylines selected.
        (setq ss_length2       (- ss_length1 (1+ ssC1))
              ssC2             ssC1
              flag_Intersects  nil
        );setq

        (repeat ss_length2
          (setq POLYLINE2_ename    (ssname ss_POLYLINES (setq ssC2  (1+ ssC2)))
                obj_POLYLINE2      (vlax-ename->vla-object POLYLINE2_ename)

                StartParam2        (vlax-curve-getStartParam obj_POLYLINE2)
                EndParam2          (vlax-curve-getEndParam obj_POLYLINE2)
                Param2             StartParam2
                dps_Params2        nil

                Coordinates2_list  nil
          );setq

          (repeat (1+ (fix EndParam2))
            (setq PointAtParam2_list  (vlax-curve-getPointAtParam obj_POLYLINE2 Param2)
                  dps_Params2         (append dps_Params2 (list (cons Param2 PointAtParam2_list)))
                  Coordinates2_list   (append Coordinates2_list (list (car PointAtParam2_list) (cadr PointAtParam2_list) 0.0))
                  Param2              (+ Param2 1.0)
            );setq
          );repeat (1+ (fix EndParam2))


          ;;  <!-- Copy obj_POLYLINE2 into block created for intersection processing geometry.
          (setq Objects1_sa (vlax-make-safearray vlax-vbObject '(0 . 0)))

          (vlax-safearray-fill Objects1_sa (list obj_POLYLINE2))

          (setq Objects2_var      (vlax-invoke-method obj_AD 'CopyObjects Objects1_sa col_Block)
                Objects2_list     (vlax-safearray->list (vlax-variant-value Objects2_var))
                obj_POLYLINE2:2D  (car Objects2_list)
                obj_POLYLINE2:3D  (vlax-invoke-method obj_POLYLINE2:2D 'Copy)
          );setq


          ;;  Flatten obj_POLYLINE2:2D i.e. Z = 0.0
          (setq Coordinates2_sa  (vlax-make-safearray vlax-vbDouble (cons 0 (1- (length Coordinates2_list)))))

          (vlax-safearray-fill Coordinates2_sa Coordinates2_list)

          (setq Coordinates2_var  (vlax-make-variant Coordinates2_sa (logior vlax-vbArray vlax-vbDouble)))

          (vlax-put-property obj_POLYLINE2:2D 'Coordinates Coordinates2_var)
          (vlax-invoke-method obj_POLYLINE2:2D 'Update)
          ;;  -->


          ;;  <!-- Check for intersection.
          (setq Inters1_var  (vlax-invoke-method obj_POLYLINE1:2D 'IntersectWith obj_POLYLINE2:2D acExtendNone)
                Inters1_sa   (vlax-variant-value Inters1_var)
          );setq

          (cond
            (  (not (minusp (vlax-safearray-get-u-bound Inters1_sa 1)))
              ;;  Intersects.
              (setq Inters1_list     (vlax-safearray->list Inters1_sa)
                    flag_Intersects  T
              );setq

              (while Inters1_list
                (setq Inters1_Point  nil)

                (repeat 3
                  (setq Inters1_Point  (append Inters1_Point (list (car Inters1_list)))
                        Inters1_list   (cdr Inters1_list)
                  );setq
                );repeat 3

                (setq ParamAtPoint1     (vlax-curve-getparamatpoint obj_POLYLINE1:2D Inters1_Point)
                      ParamAtPoint2     (vlax-curve-getparamatpoint obj_POLYLINE2:2D Inters1_Point)

                      PointAtParam1:3D  (vlax-curve-getpointatparam obj_POLYLINE1:3D ParamAtPoint1)
                      PointAtParam2:3D  (vlax-curve-getpointatparam obj_POLYLINE2:3D ParamAtPoint2)
                );setq

                (if (not (assoc ParamAtPoint1 dps_Params1))
                  (setq dps_Params1  (append dps_Params1 (list (cons ParamAtPoint1 PointAtParam1:3D))))
                );if

                (if (not (assoc ParamAtPoint2 dps_Params2))
                  (setq dps_Params2  (append dps_Params2 (list (cons ParamAtPoint2 PointAtParam2:3D))))
                );if
              );while Inters1_list
              ;;  -->


              ;;  <!-- Reconstruct obj_POLYLINE2 3D polyline vertices to include additional vertices at intersections.
              ;;  Sort dps_Params2 in numerical order.
              (setq list_params2       (mapcar 'car dps_Params2)
                    list_params2       (vl-sort list_params2 '<)
                    dps_Params2        (mapcar '(lambda (_param2) (assoc _param2 dps_Params2)) list_params2)
                    Coordinates3_list  (apply 'append (mapcar 'cdr dps_Params2))
                    Coordinates3_sa    (vlax-make-safearray vlax-vbDouble (cons 0 (1- (length Coordinates3_list))))
              );setq

              (vlax-safearray-fill Coordinates3_sa Coordinates3_list)

              (setq Coordinates3_var  (vlax-make-variant Coordinates3_sa (logior vlax-vbArray vlax-vbDouble)))

              (vlax-put-property obj_POLYLINE2 'Coordinates Coordinates3_var)
              (vlax-invoke-method obj_POLYLINE2 'Update)

              (ssadd POLYLINE2_ename ss_modified)
              ;;  -->
            )

            (T
              ;;  No intersections.
            );T
          );cond


          (vlax-invoke-method obj_POLYLINE2:2D 'Delete)
          (vlax-invoke-method obj_POLYLINE2:3D 'Delete)

          (vlax-release-object obj_POLYLINE2:2D)
          (vlax-release-object obj_POLYLINE2:3D)


          (vlax-release-object obj_POLYLINE2)
        );repeat ss_length2


        ;;  Delete copied geometry from processing block.
        (vlax-invoke-method obj_POLYLINE1:2D 'Delete)
        (vlax-invoke-method obj_POLYLINE1:3D 'Delete)
        (vlax-release-object obj_POLYLINE1:2D)
        (vlax-release-object obj_POLYLINE1:3D)
        ;;  -->


        ;;  <!-- Reconstruct obj_POLYLINE1 3D polyline vertices to include additional vertices at intersections.
        (if flag_Intersects
          (progn
            ;;  Sort dps_Params1 in numerical order.
            (setq list_params1       (mapcar 'car dps_Params1)
                  list_params1       (vl-sort list_params1 '<)
                  dps_Params1        (mapcar '(lambda (_param1) (assoc _param1 dps_Params1)) list_params1)
                  Coordinates4_list  (apply 'append (mapcar 'cdr dps_Params1))
                  Coordinates4_sa    (vlax-make-safearray vlax-vbDouble (cons 0 (1- (length Coordinates4_list))))
            );setq

            (vlax-safearray-fill Coordinates4_sa Coordinates4_list)

            (setq Coordinates4_var  (vlax-make-variant Coordinates4_sa (logior vlax-vbArray vlax-vbDouble)))

            (vlax-put-property obj_POLYLINE1 'Coordinates Coordinates4_var)
            (vlax-invoke-method obj_POLYLINE1 'Update)

            ;;  For testing change color of obj_POLYLINE1.
;            (vlax-put-property obj_POLYLINE1 'Color color_int)

            (ssadd POLYLINE1_ename ss_modified)
          );progn
        );if flag_Intersects
        ;;  -->


        (vlax-release-object obj_POLYLINE1)
      );repeat ss_length1


      ;;  "Purge" intersection processing block.
      (vlax-invoke-method col_Block 'Delete)

      (vlax-release-object col_Block)


      ;;  Grip and select.
      (sssetfirst nil ss_modified)
    );ss_POLYLINES
  );cond


  (vlax-release-object col_Blocks)
  (vlax-release-object obj_AD)


  (princ)
);c:3dpolyinters




;;------------------------------------------------------------------------------
(princ "\n3DPolyInters loaded. Start command with 3DPOLYINTERS.")
(princ)
Message 9 of 9

Anonymous
Not applicable

Thanks everyone,


I will try to modify the Trevor function so that the elevation of the new vertex will be the average of the two elevations of the intersection.

 

Best regards,

AoS

0 Likes