Jump to content

Recommended Posts

Posted

I believe you are talking of a closed polyline. One solution is to try to call the BOUNDARY command using that point and check the last entity in drawing. If there was a new polyline added, then you picked inside the base polyline.

Posted

Try this ....

 

   (defun c:Test (/ p1 p2 gr)
   ;;;;; Tharwat 28. June. 2012 ;;;;;
    (if (and (setq p1 (getpoint "\n Specify point :"))
             (setq p2 (getcorner p1 "\n Corner :"))
        )
      (while (eq (car (setq gr (grread t 15 1))) 5) (redraw)
        (foreach n '((0.5 0.5 0.0) (-0.5 0.5 0.0)(-0.5 -0.5 0.0)(0.5 -0.5 0.0))
          (grdraw
            (cadr gr)
            (mapcar '+ (mapcar (function (lambda (x) (* x (/ (getvar "VIEWSIZE") 25.))))
                (trans n 1 0))
              (cadr gr)
            )
            1
            0
          )
        )
    
        (if
          (and
            (< (car p1) (car (cadr gr)))
            (> (car p2) (car (cadr gr)))
            (> (cadr p1) (cadr (cadr gr)))
            (< (cadr p2) (cadr (cadr gr)))
          )
           (princ "\n inside ...... ")
           (princ "\n outside ..... ")
        )
      )
    )
    (redraw)
    (princ)
   )
    

  • Like 1
Posted

You may adapt this for your code:

(defun c:TestPick( / refEntity thePoint )
(setq refEntity (entlast))
(setq thePoint (getpoint "\nPick a point:"))

(command "_BOUNDARY" thePoint "")

(if (equal refEntity (entlast))
 (prompt "\nPicked outside!")
 (progn
  (prompt "\nPicked inside!")
  (entdel (entlast))
 )
)

(princ)
)

  • Like 1
Posted

Here is my method:

 

[color=GREEN];; Point Inside-p  -  Lee Mac[/color]
[color=GREEN];; Utilises a ray-casting algorithm to determine whether a[/color]
[color=GREEN];; given point (WCS) resides within a supplied object.[/color]

([color=BLUE]defun[/color] LM:PointInside-p ( pt obj [color=BLUE]/[/color] lst ray )
   ([color=BLUE]setq[/color] lst
       ([color=BLUE]vlax-invoke[/color]
           ([color=BLUE]setq[/color] ray
               ([color=BLUE]vla-addray[/color]
                   ([color=BLUE]vla-objectidtoobject[/color] ([color=BLUE]vla-get-document[/color] obj) ([color=BLUE]vla-get-ownerid[/color] obj))
                   ([color=BLUE]vlax-3D-point[/color] pt)
                   ([color=BLUE]vlax-3D-point[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] pt '(1.0 0.0 0.0)))
               )
           )
           'intersectwith obj [color=BLUE]acextendnone[/color]
       )
   )
   ([color=BLUE]vla-delete[/color] ray)
   ([color=BLUE]=[/color] 1 ([color=BLUE]logand[/color] 1 ([color=BLUE]length[/color] lst)))
)

 

To test:

([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] ent obj pnt )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] ent ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect Polyline: "[/color])))
       ([color=BLUE]if[/color] ([color=BLUE]vlax-method-applicable-p[/color] ([color=BLUE]setq[/color] obj ([color=BLUE]vlax-ename->vla-object[/color] ent)) 'intersectwith)
           ([color=BLUE]while[/color] ([color=BLUE]setq[/color] pnt ([color=BLUE]getpoint[/color] [color=MAROON]"\nPick Point: "[/color]))
               ([color=BLUE]if[/color] (LM:PointInside-p ([color=BLUE]trans[/color] pnt 1 0) obj)
                   ([color=BLUE]alert[/color] [color=MAROON]"Point is INSIDE"[/color])
                   ([color=BLUE]alert[/color] [color=MAROON]"Point is OUTSIDE"[/color])
               )
           )
           ([color=BLUE]princ[/color] [color=MAROON]"\nInvalid Object selected."[/color])
       )
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

 

More rigorous testing may be required to account for the case in which the projected ray is parallel to the intersecting edge. But the above will suffice for the majority of general applications.

  • Like 1
Posted
Here is my method:

 

[color=GREEN];; Point Inside-p  -  Lee Mac[/color]
[color=GREEN];; Utilises a ray-casting algorithm to determine whether a[/color]
[color=GREEN];; given point (WCS) resides within a supplied object.[/color]

 

More rigorous testing may be required to account for the case in which the projected ray is parallel to the intersecting edge. But the above will suffice for the majority of general applications.

 

I like it :thumbsup:

 

Thank you for sharing.

Posted

Lee, It's great. Too complicated for me. Thanks for sharing, Tharwat, MSasu, and Lee Mac.

Posted

Uffff. Hello Marko. Admittedly. I've searched but have not found it. I apologize. Now we have four methods. Apologies. Thanks.

The blood not watered me well the brain. :D:D. Thanks

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