Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

John Uhden's @cv_inside function

16 views
Skip to first unread message

Doug Broad

unread,
Sep 7, 2003, 5:20:48 PM9/7/03
to

John,
Do you mean "concurrent" rather than "congruent"?

Sorry it didn't work out for you. I still believe that
the intersectwith method has possibilities if its shortcomings,
specifically 1)rays that go through verticies and 2) rays that touch
tangents are thrown out as reliable directions.

A loop that uses rays at different directions until one does not
go through one of these points should be reliable.

I did very much like your use of entmakex for the temporary ray.
I will have to look at that in the future.

Regards,
Doug


"John Uhden" <juh...@cadlantic.com> wrote in message
news:36856518B4DF92E6...@in.WebX.maYIadrTaRb...
> It's official...
> I apologize for wasting eveyone's time, but I've concluded that ray casting
> using the IntersectWith method is too faulty for use with polylines, as Doug has
> doggedly demonstrated. The final straw was aiming a ray dead through the middle
> of two (2) congruent segments of one polyline and getting one intersection point
> in return.
>
> Looks like I'd better break out that old R12 technology and polish it up. :/
>
> --
> John Uhden, Cadlantic/formerly CADvantage
> http://www.cadlantic.com
> Sea Girt, NJ
>
>
<snip>


Luis Esquivel

unread,
Sep 8, 2003, 9:38:48 AM9/8/03
to
And in case still this is useful here is my last try:

;;; 9/4/03 - 6:36 AM 9/8/2003 by Luis Esquivel
;;; http://www.draftteam.com

(defun point-inside-region-p
(vla_poly pt aid-pt pts / vla_line lst_value param result)
(setq
result
(cond
((and (setq param (vlax-curve-getparamatpoint vla_poly pt))
(eq (type (- param (fix param))) 'real))
nil)
((and (not (vl-position (list (car pt) (cadr pt)) pts))
(not
(vl-catch-all-error-p
(setq lst_value
(vl-catch-all-apply
'vlax-safearray->list
(list (vlax-variant-value
(vla-intersectwith
vla_poly
(setq vla_line
(vla-addline
(vla-objectidtoobject
(vla-get-document
vla_poly)
(vla-get-ownerid
vla_poly))
(vlax-3d-point pt)
(vlax-3d-point aid-pt)))
acextendnone))))))))
(fix (/ (length lst_value) 3.0)))))
(vl-catch-all-apply 'vla-delete (list vla_line))
(if (numberp result)
(not (zerop (rem result 2)))))

(defun C:TEST (/ ent elst pt vla_poly lc uc)
(if
(and (setq ent (car (entsel "\nSelect a polyline: ")))
(eq (cdadr (setq elst (entget ent))) "LWPOLYLINE")
(eq (vla-get-closed
(setq vla_poly (vlax-ename->vla-object ent)))
:vlax-true)
(setq pt (getpoint "\nTest point: ")))
(progn
(vla-getboundingbox vla_poly 'lc 'uc)
(point-inside-region-p
vla_poly
pt
(polar pt
(/ pi 2.0)
(distance (vlax-safearray->list lc)
(vlax-safearray->list uc)))
(mapcar
'cdr
(vl-remove-if-not
(function (lambda (item) (eq (car item) 10)))
elst))))))
(princ)


John Uhden

unread,
Sep 7, 2003, 6:35:48 PM9/7/03
to
Conwhatever... the results may not indicate the true number of intersections, so
it's not reliable <period>.

Entmakex is fun. That's what we used to have to use to create xrecords.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Doug Broad" <dbr...@earthlink.net> wrote in message
news:36A890A3FDB7940B...@in.WebX.maYIadrTaRb...

Joe Burke

unread,
Sep 8, 2003, 9:28:27 AM9/8/03
to
John,

I was away for a few days so I missed recent posts.

You certainly didn't waste my time, and I doubt you wasted your own. I mean, if
ray casting and IntersectWith doesn't get it, you learned something, right?
Isn't that what programming is about? Look for another solution...

Tony's first post in this thread indicated these methods may never be
bulletproof. I'm not sure that means we should abandon the idea. Doug still
seems to have some faith.

Certainly, if a bulletproof method is possible, it would be welcome. Otherwise
the question may boil down to a combination of methods which put the wrong
answer so far at the extreme of likelihood as to be negligible.

Joe Burke

"John Uhden" <juh...@cadlantic.com> wrote in message
news:36856518B4DF92E6...@in.WebX.maYIadrTaRb...
> It's official...
> I apologize for wasting eveyone's time, but I've concluded that ray casting
> using the IntersectWith method is too faulty for use with polylines, as Doug
has
> doggedly demonstrated. The final straw was aiming a ray dead through the
middle
> of two (2) congruent segments of one polyline and getting one intersection
point
> in return.
>
> Looks like I'd better break out that old R12 technology and polish it up. :/
>
> --
> John Uhden, Cadlantic/formerly CADvantage
> http://www.cadlantic.com
> Sea Girt, NJ
>
>

> "Doug Broad" <dbr...@earthlink.net> wrote in message

> news:37BD2FA28F583AC9...@in.WebX.maYIadrTaRb...
> > Hi John,
> >
> > If you can put the missing line(s) back in and post it, I would
> > be glad to test it.


> >
> > Regards,
> > Doug
> >
> >
> > "John Uhden" <juh...@cadlantic.com> wrote in message

> > news:447E7E38FF43FEAE...@in.WebX.maYIadrTaRb...
> > > Doug: I saw your post from work today (no OE to use to reply thanks to
> > > firewall).
> > >
> > > All I was missing was a line I had taken out:
> > >
> > > (= (rem (length Points1) 6) 3)
> > >
> > > The whole idea is really simple... you are inside a room when there is a
> wall in
> > > front of you and a wall in back of you.
> > >
> > <snip>
> >
> >
>


Luis Esquivel

unread,
Sep 8, 2003, 2:36:25 PM9/8/03
to
Okay this is the latest one - hope that someone find it at least useful ;-)

;;; 9/4/03 - 6:36 AM 9/8/2003 - 9/8/03 by Luis Esquivel
;;; http://www.draftteam.com

(defun get-xy (lst_xyz / cont ints)
(setq cont 0)
(while (< cont (length lst_xyz))
(setq ints (append ints
(list (list (nth cont lst_xyz)
(nth (1+ cont) lst_xyz)))))
(setq cont (+ cont 3)))
ints)

(defun angvec (vect)
(cond
((equal (car vect) 0 0.0001)
(if (minusp (cadr vect))
(* 1.5 pi)
(/ pi 2)))
((equal (car vect) -1 0.0001) pi)
((equal (cadr vect) 0 0.0001)
(if (minusp (car vect))
pi
0))
(T (atan (/ (cadr vect) (car vect))))))

(defun point-inside-region-p
(vla_poly pt aid-pt pts / vla_line lst_value param result)
(setq
result
(cond

;; verifies if the test-point is not on any polyline segment


((and (setq param (vlax-curve-getparamatpoint vla_poly pt))
(eq (type (- param (fix param))) 'real))
nil)

;; verifies if the test-point is not a vertex


((and (not (vl-position (list (car pt) (cadr pt)) pts))
(not
(vl-catch-all-error-p
(setq lst_value
(vl-catch-all-apply
'vlax-safearray->list
(list (vlax-variant-value
(vla-intersectwith
vla_poly
(setq vla_line
(vla-addline
(vla-objectidtoobject
(vla-get-document
vla_poly)
(vla-get-ownerid
vla_poly))
(vlax-3d-point pt)
(vlax-3d-point aid-pt)))
acextendnone))))))))

;; verifies if any of the intersection points
;; is not part of the vertex's
(if (not (vl-some
(function (lambda (i) (vl-position i pts)))
(get-xy lst_value)))
(fix (/ (length lst_value) 3.0))))))

(vl-catch-all-apply 'vla-delete (list vla_line))

;;; a mickey mouse solution
;;; (if (vl-some (function (lambda (int) (osnap int "_tan")))
;;; (get-xy lst_value))
;;; (setq result nil))

;; not a mickey mouse solution, I think a better approach below
(if (and (not


(vl-catch-all-error-p
(setq lst_value
(vl-catch-all-apply
'vlax-safearray->list
(list (vlax-variant-value
(vla-intersectwith
vla_poly
(setq vla_line
(vla-addline
(vla-objectidtoobject
(vla-get-document
vla_poly)
(vla-get-ownerid
vla_poly))
(vlax-3d-point pt)
(vlax-3d-point aid-pt)))
acextendnone)))))))

;; verifies if any of the intersection points
;; is not tangent
(vl-some (function
(lambda (int)

(setq vect
(vlax-curve-getfirstderiv
vla_poly
(vlax-curve-getparamatpoint vla_poly int)))
(equal (angvec vect) (/ pi 2.0) 1.0e-009)))
(get-xy lst_value)))
(setq result nil))

(vl-catch-all-apply 'vla-delete (list vla_line))

(if (numberp result)
(not (zerop (rem result 2)))))

(defun C:TEST (/ ent elst pt vla_poly lc uc)
(if
(and (setq ent (car (entsel "\nSelect a polyline: ")))
(eq (cdadr (setq elst (entget ent))) "LWPOLYLINE")
(eq (vla-get-closed
(setq vla_poly (vlax-ename->vla-object ent)))
:vlax-true)
(setq pt (getpoint "\nTest point: ")))
(progn
(vla-getboundingbox vla_poly 'lc 'uc)
(point-inside-region-p
vla_poly
pt

;; remove aid-pt setq - was for testing only
(setq aid-pt (polar pt


(/ pi 2.0)
(distance (vlax-safearray->list lc)

(vlax-safearray->list uc))))

;; remove pts setq - was for testing only
(setq pts


(mapcar
'cdr
(vl-remove-if-not
(function (lambda (item) (eq (car item) 10)))
elst)))

))))
(princ)


John Uhden

unread,
Sep 8, 2003, 8:17:30 PM9/8/03
to
You hold the greatest conversations! :)

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Luis Esquivel" <www.draftteam.com> wrote in message
news:574DAB18D4A73F9F...@in.WebX.maYIadrTaRb...
> And after doing some tests using big lists - the best approach is to use
> objectarx, but was a nice excercise and also to talk just to my self.
>
> :|
>
>

Luis Esquivel

unread,
Sep 8, 2003, 12:09:12 PM9/8/03
to
Wait, I forgot the tangency test... let me do it - I will re-post it in a
little while...

Luis.

Luis Esquivel

unread,
Sep 8, 2003, 8:27:29 PM9/8/03
to
I know....

good night - time to fly to my house...

Luis Esquivel

unread,
Sep 8, 2003, 12:25:46 PM9/8/03
to
hmmmm... tangency won't be to easy to check... I will look at your sample
and see if I can use something ... :(

L.

Doug Broad

unread,
Sep 8, 2003, 12:35:23 PM9/8/03
to
Luis,

To check tangency, you must find the firstderivative at
the intersection point. Something like: (check my spelling)
(setq deriv (vlax-curve-getfirstderiv polyobj (vlax-curve-paramatpoint <point>)))

Then you must convert it to an angle so you can compare the ray's angle.
The first derivative is not a direction vector, so you can't use it as is.

(atan deriv) will give you the angle. Then you must compare the
ray angle and that angle and the ray angle and that angle + pi.

The comparisons should use equal and a reasonable fuzz factor.

Regards,
Doug


"Luis Esquivel" <www.draftteam.com> wrote in message

news:05C93921FB94B5E0...@in.WebX.maYIadrTaRb...

Luis Esquivel

unread,
Sep 9, 2003, 12:20:33 PM9/9/03
to

"Doug Broad" <dbr...@nash.cc.nc.us> wrote in message
news:F723319B68E08341...@in.WebX.maYIadrTaRb...
> Thanks Luis,
> Please let me know if you discover any situtations in which
> it doesn't work. There is also an error in my
getvalidintersectionswithray
> subroutine. It should read

I sent my function yesterday to the people of arqcom software
(http://www.arqcom.com.mx) to perform a test, they told me that there where
not much difference in using their built arx function against mine only
until they did several run tests, the conclusion was that if my function was
just for exporadic use was okay, but if where needed to manipulate big
lists, then it won't be to efficient, also they recomend me a paul bourke
algorithm: http://astronomy.swin.edu.au/~pbourke/geometry/insidepoly/


Luis.


Luis Esquivel

unread,
Sep 9, 2003, 6:56:32 PM9/9/03
to
Doug,

I owe you several beers or drinks if you go by the way go to the AU the next
December, I will be there the last day Friday the 5th as a guest visitor.
Now talking about your function I will use yours now this end of this thread
for me for sure, see ya' master.

Luis.

"Luis Esquivel" <www.draftteam.com> wrote in message

news:D3BD287055B91939...@in.WebX.maYIadrTaRb...
> Ignore the last post I have to do more test of my own.
>
> (hitting my face randomly - what a ....)
>
>


Joe Burke

unread,
Sep 9, 2003, 7:29:24 PM9/9/03
to
Doug,

OK


"Doug Broad" <dbr...@earthlink.net> wrote in message

news:061EBA90F4F82A65...@in.WebX.maYIadrTaRb...
> Joe,
> Change the argument name to pt-wcs and forget the other changes.
> That's what I'm going to do.
>
>
>
>
> "Joe Burke" <job...@hawaii.rr.com> wrote in message
> news:AC1E8279A26CD4EB...@in.WebX.maYIadrTaRb...
> > Doug,
> >
> > I see now why, "it still operates", but I'll change it anyway.
> >
> > I won't have a chance to test until this evening.
> >
> > Thanks
> > Joe
> <snip>
>
>


Doug Broad

unread,
Sep 9, 2003, 12:00:50 AM9/9/03
to
Hi Luis,
Things were very busy today. Sorry to get back so late.
There are still situtations that your routine does not catch.

I am not sure I understand your code completely.

I am also posting some code that seems to work. I would
say it is in Beta testing mode. It uses some code adapted
from Reini Urban (hope that's OK Reini).

Regards,
Doug


"Luis Esquivel" <www.draftteam.com> wrote in message

news:231AA3840EA55DDF...@in.WebX.maYIadrTaRb...

insidepoly2.lsp
random-reini.lsp

Doug Broad

unread,
Sep 9, 2003, 5:02:39 PM9/9/03
to
Thanks Joe,
In this particular case, it still operates but the subroutine would
not work well if called from another program. Thanks for the notice.

Did you test the program out on your favorite odd shapes?

Regards,
Doug


"Joe Burke" <job...@hawaii.rr.com> wrote in message

news:600310CD3B9E6F6F...@in.WebX.maYIadrTaRb...
> Doug,
>
> Just to confirm. There's two places in GetValidIntersectionsWithRay where
> "pt-wcs" should be "pt"?
>
> (vlax-3d-point pt-wcs)
> (trans (polar pt-wcs 0 1) 1 0)
>
> Joe


>
>
> > Please let me know if you discover any situtations in which
> > it doesn't work. There is also an error in my getvalidintersectionswithray
> > subroutine. It should read
> >

> > (setq varpt (vlax-3d-point pt) ...
> >
> > This should not affect the results in this application.
>
>


Luis Esquivel

unread,
Sep 8, 2003, 11:58:53 AM9/8/03
to
Thank you Doug,

Then here is:

;;; 9/4/03 - 6:36 AM 9/8/2003 - 9/8/03 by Luis Esquivel
;;; http://www.draftteam.com

(defun get-xy (lst_xyz / cont ints)


(setq cont 0)
(while (< cont (length lst_xyz))
(setq ints (append ints
(list (list (nth cont lst_xyz)
(nth (1+ cont) lst_xyz)))))
(setq cont (+ cont 3)))
ints)

(defun point-inside-region-p

(if (not (vl-some
(function (lambda (i) (vl-position i pts)))
(get-xy lst_value)))
(fix (/ (length lst_value) 3.0))))))

"Doug Broad" <dbr...@nash.cc.nc.us> wrote in message

news:B763618F88D1635D...@in.WebX.maYIadrTaRb...
> Hi Luis,
> I am attaching an image showing a situation in which your algorithm might
> fail. Its still possible but the situtations where the ray goes through
verticies
> and tangents must be ignored so the algorithm must be flexible enough to
> check and loop.
>
> Regards,
> Doug


Doug Broad

unread,
Sep 9, 2003, 11:15:38 AM9/9/03
to
Thanks Luis,

Please let me know if you discover any situtations in which
it doesn't work. There is also an error in my getvalidintersectionswithray
subroutine. It should read

(setq varpt (vlax-3d-point pt) ...

This should not affect the results in this application.

"Luis Esquivel" <www.draftteam.com> wrote in message

news:86EE6DB77F9FD42C...@in.WebX.maYIadrTaRb...


> > Hi Luis,
> > Things were very busy today. Sorry to get back so late.
> > There are still situtations that your routine does not catch.
> >
> > I am not sure I understand your code completely.
>

> No problem Doug, I think that my participation on this thread is enough, I
> will study your code.
>
> Thanks,
> Luis.
>
>


Luis Esquivel

unread,
Sep 9, 2003, 9:42:03 AM9/9/03
to
> Hi Luis,
> Things were very busy today. Sorry to get back so late.
> There are still situtations that your routine does not catch.
>
> I am not sure I understand your code completely.

No problem Doug, I think that my participation on this thread is enough, I

Doug Broad

unread,
Sep 10, 2003, 9:12:01 AM9/10/03
to
Hi Joe,
I can't replicate your results. It works for me as indicating outside.
I tried test point -1,-1 and -1,1. Please recheck the coordinates
you just posted. Also, did you BTW change both the arguments from
pt to pt-wcs and keep the other changes pt-wcs to pt. If so then
you might have a problem. Take the original I posted and change
just change to

(defun GetValidIntersectionsWithRay (pt-wcs .......

"Joe Burke" <job...@hawaii.rr.com> wrote in message

news:C973ED70B1208177...@in.WebX.maYIadrTaRb...
> Doug,
>
> A test with one of your shapes: ((0 0) (1 1) (2 0) (2 2) (0 2)) and closed.
> Outside test point at (-1 -1) Result: Odd number of intersections: Point is
> inside. Bummer.
>
> The ray intersects two sides and the vertex at the center of the pline.
>
> Please confirm I haven't done something wrong. The breakage seems too easy. I
> loaded Reini's functions and insidepoly2. Then ran the "test" function. I also
> commented out (vla-delete ray). The argument to GetValidIntersectionsWithRay is
> pt-wcs as you suggested. References to it are consistent.
>
> Joe


>
> "Doug Broad" <dbr...@earthlink.net> wrote in message

> news:2543FAEF8B26CF98...@in.WebX.maYIadrTaRb...

Joe Burke

unread,
Sep 9, 2003, 3:44:03 PM9/9/03
to
Doug,

I don't believe it. I was fooling with John's original code yesterday. My
thought: if the second ray point was totally random, using getvar "date"
somehow, the chance the ray would pass though a vertex would be virtually
non-existent.

Joe :-)

Luis Esquivel

unread,
Sep 9, 2003, 6:46:37 PM9/9/03
to
Here is the last update, please let me know if works...:

;;; 3:45 PM 9/9/2003
;;; Luis Esquivel

(defun random ()
(setq seed (if seed
(rem (+ (* seed 15625.7) 0.21137152) 1)
0.3171943)))

(defun get-xy (lst_xyz / cont ints)
(setq cont 0)
(while (< cont (length lst_xyz))
(setq ints (append ints
(list (list (nth cont lst_xyz)
(nth (1+ cont) lst_xyz)))))
(setq cont (+ cont 3)))
ints)

(defun angvec (vect)
(cond
((equal (car vect) 0 0.0001)
(if (minusp (cadr vect))
(* 1.5 pi)
(/ pi 2)))
((equal (car vect) -1 0.0001) pi)
((equal (cadr vect) 0 0.0001)
(if (minusp (car vect))
pi
0))
(T (atan (/ (cadr vect) (car vect))))))

(defun point-inside-polyline

(vl-catch-all-apply 'vla-delete (list vla_line))

(if (and (not

(vl-catch-all-apply 'vla-delete (list vla_line))

(defun C:TEST-LUIS (/ ent elst pt vla_poly lc uc)


(if
(and (setq ent (car (entsel "\nSelect a polyline: ")))
(eq (cdadr (setq elst (entget ent))) "LWPOLYLINE")
(eq (vla-get-closed
(setq vla_poly (vlax-ename->vla-object ent)))
:vlax-true)
(setq pt (getpoint "\nTest point: ")))
(progn
(vla-getboundingbox vla_poly 'lc 'uc)

(point-inside-polyline
vla_poly
pt

;; remove aid-pt setq - was for testing only
(setq aid-pt (polar pt

(random)

Joe Burke

unread,
Sep 9, 2003, 5:55:35 PM9/9/03
to
Doug,

I see now why, "it still operates", but I'll change it anyway.

I won't have a chance to test until this evening.

Thanks
Joe

"Doug Broad" <dbr...@earthlink.net> wrote in message
news:2543FAEF8B26CF98...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Sep 9, 2003, 7:07:58 PM9/9/03
to
Hi Luis,
Enjoyed the thread. I think the only way I'm going to
get to AU is if someone wants me to present. Have
fun!

Regards,
Doug


"Luis Esquivel" <www.draftteam.com> wrote in message

news:22AE45CA8FD19269...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Sep 9, 2003, 2:03:52 PM9/9/03
to
Thanks for the nice link Luis.

In this thread, we were attempting to address a more complicated situation
where the shape was not merely polygonal but also made of curved edges.
Those curved edges could create shapes that would make it appear that
a point was within but actually be outside based on angle sum. This thread
addressed also figures that, while not self-intersection, would not be categorized
as convex polygons. The thread did not address regions, only polylines.

Other than implementing the task with a faster programming language,
I don't think a lot of improvement can be made to the one I posted last
night. I would be happy to be wrong about that, however.

The important difference between mine and John's and (I think) yours
is that mine uses a loop to eliminate directions that go through verticies
and tangents prior to determining the odd/even count. For most situations,
the loop is not necessary. The only extra time taken in the algorithm is that
necessary to validate that the intersections don't go through verticies and
tangents. For those situtations however, the ray angle and not the point
placement must be changed.

If the task is strictly limited to straight edged convex polygons, then simpler
and faster methods would be appropriate. I hope this is making sense.

(I was glad I waited a day to post the last version because I found some pretty
drastic errors within the simplest subfunctions converting lists to points.)

Regards,
Doug


"Luis Esquivel" <www.draftteam.com> wrote in message

news:55895C3D6DBDFBB8...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Sep 9, 2003, 7:03:43 PM9/9/03
to
Joe,
Change the argument name to pt-wcs and forget the other changes.
That's what I'm going to do.

"Joe Burke" <job...@hawaii.rr.com> wrote in message

news:AC1E8279A26CD4EB...@in.WebX.maYIadrTaRb...


> Doug,
>
> I see now why, "it still operates", but I'll change it anyway.
>
> I won't have a chance to test until this evening.
>
> Thanks
> Joe

<snip>


Joe Burke

unread,
Sep 9, 2003, 4:22:04 PM9/9/03
to
Doug,

Just to confirm. There's two places in GetValidIntersectionsWithRay where
"pt-wcs" should be "pt"?

(vlax-3d-point pt-wcs)
(trans (polar pt-wcs 0 1) 1 0)

Joe


Luis Esquivel

unread,
Sep 8, 2003, 12:44:28 PM9/8/03
to
Thank you Doug,

Looks like I do not have anything to do (as normal).... I think I have here
some of my base code, I might have something already, and also will follow
your advice.

Joe Burke

unread,
Sep 10, 2003, 7:27:08 AM9/10/03
to
Doug,

A test with one of your shapes: ((0 0) (1 1) (2 0) (2 2) (0 2)) and closed.
Outside test point at (-1 -1) Result: Odd number of intersections: Point is
inside. Bummer.

The ray intersects two sides and the vertex at the center of the pline.

Please confirm I haven't done something wrong. The breakage seems too easy. I
loaded Reini's functions and insidepoly2. Then ran the "test" function. I also
commented out (vla-delete ray). The argument to GetValidIntersectionsWithRay is
pt-wcs as you suggested. References to it are consistent.

Joe

"Doug Broad" <dbr...@earthlink.net> wrote in message
news:2543FAEF8B26CF98...@in.WebX.maYIadrTaRb...

Luis Esquivel

unread,
Sep 9, 2003, 6:50:29 PM9/9/03
to

John Uhden

unread,
Sep 9, 2003, 9:29:10 PM9/9/03
to
Doug:

Where I gave up was encountering the situation where the ray would pass through
con<whatever>, say colinear, segments and return just one intersection instead
of two.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Doug Broad" <dbr...@earthlink.net> wrote in message

news:94133BFF10226C5D...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Sep 5, 2003, 9:25:48 PM9/5/03
to
It's official...
I apologize for wasting eveyone's time, but I've concluded that ray casting
using the IntersectWith method is too faulty for use with polylines, as Doug has
doggedly demonstrated. The final straw was aiming a ray dead through the middle
of two (2) congruent segments of one polyline and getting one intersection point
in return.

Looks like I'd better break out that old R12 technology and polish it up. :/

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Doug Broad" <dbr...@earthlink.net> wrote in message

news:37BD2FA28F583AC9...@in.WebX.maYIadrTaRb...
> Hi John,
>
> If you can put the missing line(s) back in and post it, I would
> be glad to test it.
>
> Regards,
> Doug
>
>
> "John Uhden" <juh...@cadlantic.com> wrote in message
> news:447E7E38FF43FEAE...@in.WebX.maYIadrTaRb...
> > Doug: I saw your post from work today (no OE to use to reply thanks to
> > firewall).
> >
> > All I was missing was a line I had taken out:
> >
> > (= (rem (length Points1) 6) 3)
> >
> > The whole idea is really simple... you are inside a room when there is a
wall in
> > front of you and a wall in back of you.
> >
> <snip>
>
>

Luis Esquivel

unread,
Sep 9, 2003, 2:44:17 PM9/9/03
to
Great... :-(


"Doug Broad" <dbr...@nash.cc.nc.us> wrote in message

news:F4223CD026588156...@in.WebX.maYIadrTaRb...
>
> Luis,
> Attached is an image of a polygon that tests nil at the point
> shown.
>
> HTH.


>
>
> "Luis Esquivel" <www.draftteam.com> wrote in message

> news:A532EA80826CE791...@in.WebX.maYIadrTaRb...


> > > There are still situtations that your routine does not catch.
> >

> > Do you have any sample?
> >
> > Have a look on the type of polygons I used for test and if you have any
> > other possibility let me know.
> >
> > Luis.
> >
> >
>
>
> --------------------------------------------------------------------------
------
>
>


----------------------------------------------------------------------------
----


R. Robert Bell

unread,
Sep 10, 2003, 11:14:18 AM9/10/03
to
"Doug Broad" <dbr...@earthlink.net> wrote in message
news:1755BF371ED636C5...@in.WebX.maYIadrTaRb...
|
| Sorry, but, con<whatever> doesn't mean anything to me.


Congruent, or concurrent, or convoluted... ;-)

From *way* earlier in the thread.


Joel Roderick

unread,
Sep 11, 2003, 8:47:07 AM9/11/03
to
Doug,
"Boundary" is the actual command name....


"Doug Broad" <dbr...@earthlink.net> wrote in message

news:B1F5697111481F60...@in.WebX.maYIadrTaRb...
> Tony,
> Thanks for that info. Where is bpoly documented?
> There is no documentation in the help files.
>
> Certainly would be more convenient to use bpoly if it
> could be used in this way.
>
> Regards,
> Doug
>
>
>
> "Tony Tanzillo" <tony.tanzillo at caddzone dot com> wrote in message
> news:94989ADA0F5475EB...@in.WebX.maYIadrTaRb...
> > BPOLY/Boundary can work with a selection set as well as
> > the default (everything visible in the viewport).
> >
> > --
> > AcadXTabs: Document Tabs for AutoCAD
> > http://www.acadxtabs.com
> >
> >
>
>


Joe Burke

unread,
Sep 10, 2003, 3:39:48 PM9/10/03
to
Doug,

Right. My mistake, I meant test point at -1,1.

I've run numerous tests. Sometimes it works right, other times not, using the
same shape mentioned previously. Always with test point at -1,1 *relative* to
the lower left vertex of the pline. I say relative to because if I copy the
pline to various locations, it works at some locations. Strange, I can't see any
pattern in the behavior.

I re-downloaded your post. Made this change:

> (defun GetValidIntersectionsWithRay (pt-wcs .......

And commented out: (vla-delete ray)

I'll post an example file to CF.

Thanks
Joe

"Doug Broad" <dbr...@nash.cc.nc.us> wrote in message

news:B0F4CE44A52C322D...@in.WebX.maYIadrTaRb...

Joe Burke

unread,
Sep 10, 2003, 4:19:49 PM9/10/03
to
Doug,

Example file in CF. Really curious...

Joe


"Doug Broad" <dbr...@earthlink.net> wrote in message

news:014F85692B9D430E...@in.WebX.maYIadrTaRb...
> Hi Joe,
> Just tested it about 200 times and didn't get a single error.
> I can't explain why you might be getting different results.
> Anyone else?


>
> Regards,
> Doug
>
> "Joe Burke" <job...@hawaii.rr.com> wrote in message

> news:1CFA71CD57FFCA2A...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Sep 10, 2003, 3:57:23 PM9/10/03
to
Hi Joe,
Just tested it about 200 times and didn't get a single error.
I can't explain why you might be getting different results.
Anyone else?

Regards,
Doug

"Joe Burke" <job...@hawaii.rr.com> wrote in message

news:1CFA71CD57FFCA2A...@in.WebX.maYIadrTaRb...

Luis Esquivel

unread,
Sep 8, 2003, 5:50:02 PM9/8/03
to
And after doing some tests using big lists - the best approach is to use
objectarx, but was a nice excercise and also to talk just to my self.

:|


Luis Esquivel

unread,
Sep 11, 2003, 2:01:39 PM9/11/03
to
Joe,

What I typed there is what I remember I need to take look in my old r12
customization book, as far as new acad releases don't know if bpoly is the
same as c:bpoly (I always been using (bpoly pt))

I do not have a bpoly-def I wrote a long time ago for the coordinates
presicion and was for r12, I think I gave a copy to Devin (he is one of the
lisp getto frecuent visitor too).

Luis.

"Joe Burke" <job...@hawaii.rr.com> wrote in message

news:D60F8CF640262773...@in.WebX.maYIadrTaRb...
> Hi Luis,
>
> > (bpoly <internal-point> [optional <sel-set>] [optional <ray-cast>])
>
> Using A2k2. I can't get the optional arguments to work. Returns nil.
>
> (bpoly pt ss)
> or
> (bpoly pt ss t)
>
> Where ss is selection set containing a single closed lwpolyline.
>
> Joe
>
>
> > also it will be very easy to make a loop using (bherrs) and have a list
of
> > vectors in case bpoly produces and error, also we can change the
coordinates
> > precision too.
> >
> > Luis.

Joe Burke

unread,
Sep 10, 2003, 7:59:16 PM9/10/03
to
Doug,

That got it. Glad to be of assistance.

Now I wonder what John thinks...

Many thanks as usual :-)
Joe

"Doug Broad" <dbr...@earthlink.net> wrote in message

news:73F7D666956CB556...@in.WebX.maYIadrTaRb...
> Hi Joe,
>
> Thanks for that information. I provided the first direction at 0.0 angle
> so that it would be easy for you guys to set up a trap for the logic. If
> I had used the random direction as the first direction then we couldn't
> discuss the problems. Glad it worked.
>
> Apparently the 1,1 vertex of your polyline has an x value of
> 0.99999999999555 or something like that and vl-position does
> not compare properly in some strange situtations like that.
>
> I substitutes vl-position with a custom subroutine, ptmember.
> It seems to work. Thanks for spotting that.
>
> It may be wise to use 3 random ray directions and have the
> algorithm continue until the "vote" is either unanimous or
> overwhelming. ;-)
>
> Get Random-Reini from previous post.


>
>
> Regards,
> Doug
>
> "Joe Burke" <job...@hawaii.rr.com> wrote in message

> news:3AC68574BED4B0FE...@in.WebX.maYIadrTaRb...


--------------------------------------------------------------------------------


;;D. C. Broad 9/8/03
;;Copyright 2003. All rights reserved except
;;Non-commercial use freely granted.

;|An inductive method of determining whether a point is inside
based on the intersection of a ray with the figure. Although
it is unprovable, it should be a highly reliable of determining
whether a point is inside a figure. It uses a random number generator
to generate angles that are unlikely to cause problems with
most polygonal figures. Polylines may include curved segments
but may not be self-intersecting for the logic to hold. Both
the polyline and the point must be on the world coordinate plane.
Limitations: Z elevation = 0.
Bug fix: 9/9/03 getvalidintersectionswithray argument pt to pt-wcs
Revision: 9/10/03 added ptmember - Joe Burke discovered that
using vl-position is insufficient to compare points due to round
off error.
|;


;;Random number program by Reini Urban based on an algorithm
;;by Serge Pashkov
(or random (load "random-reini"))

;;turn a flat 3d list into a point list
(defun groupby3 (lst)
(cond
((null lst) nil)
((cons (list (car lst) (cadr lst)(caddr lst))
(groupby3 (cdddr lst))
))))

;;Turn a coordinate list (2d) into a point list (3d)
(defun coordsToPoints (lst)
(cond
((null lst) nil)
((cons (list (car lst)(cadr lst) 0.0)
(coordsToPoints (cddr lst))))))

;;Is a point very close to a member of the list?
(defun ptmember (pt ptlist)
(vl-some '(lambda (x) (equal pt x 1e-10))
ptlist))

;;----------------------------------------------------------------------
;;Search the number of times specified for a valid set of intersections.
;;Arguments (WCS point, polyline object, number of loops to try, polyline
coordinate list)
(defun GetValidIntersectionsWithRay (pt-wcs poly maxtries
coords / varpt
ray intersections
ang tries fullcircle
)
(setq varpt (vlax-3d-point pt-wcs) ;;variant point value of pt
ang 0.0 ;;initial ray angle
fullcircle (* 2 pi) ;;360 degrees
ray (vla-addray ;;intersecting ray
(vla-objectidtoobject
(vla-get-document poly)
(vla-get-ownerid poly)
)
varpt
(vlax-3d-point
(trans (polar pt-wcs 0 1) 1 0)) ;;ray to the right
)
intersections (vlax-invoke ray "intersectwith"
poly acextendnone) ;;intersections if any
tries 0 ;;loop counter
)
;;loop until ray direction is valid ------------
(while (and (not (validintersections ang intersections poly coords))
(< tries maxtries))

(setq ang (- (random fullcircle) pi) ;;try next angle
tries (1+ tries))
(vlax-put ray
"directionvector"
(list (cos ang) (sin ang) 0.0)) ;;set new ray direction
(setq intersections (vlax-invoke ray "intersectwith" poly acextendnone)
)
) ;;end while --------------

;;///////////////////////////////////////////////////////////
(vla-delete ray) ;;comment this out to see ray that was used.
;;///////////////////////////////////////////////////////////
(if (equal tries maxtries)
"Search Failed"
intersections
)
)

;;------------------------------------------------------------------

;;All intersections are valid if none of them hit any verticies and
;;at none of them is the curve tangent to the ray or there are
;;no intersections
;;Arguments(angle in radians, intersection list from intersectwith, polyline
object, polyline coordinates)
(defun ValidIntersections (ang intersections poly coords )
(or
(null intersections)
(and
(vl-every
'(lambda (x) (not (ptmember x coords)))
(setq intersections (groupby3 intersections) int2 intersections)
)
(vl-every
'(lambda (x / param firstder angder backang)
(setq param (vlax-curve-getparamatpoint poly x)
firstder (vlax-curve-getfirstderiv poly param)
angder (atan (cadr firstder) (car firstder))
backang (atan (- (cadr firstder)) (- (car firstder)))
)
(and
(not (equal ang angder 0.0001))
(not (equal ang backang 0.0001))
)
)
intersections
)
)
)
)


;;A convenient test program for this file.
(defun c:test ( / ob pt)
(command "ucs" "")
(setq ob (vlax-ename->vla-object (car (entsel))))
(while (setq pt (getpoint "\nSelect point: "))
(ptinsidepoly pt ob 10)
)
)


;;MAIN FUNCTION------------
;;Arguments: WCS point, vla-polyline object, number of attempts
(defun ptinsidepoly (pt-wcs poly attempts /
closest coords intersections
verbose
)
;;verbose function used to optionally report
(setq verbose list)
;/////////////////////////////////////////////////////////
(setq verbose princ) ;comment this out for no explanations
;/////////////////////////////////////////////////////////
(setq closest (vlax-curve-getclosestpointto poly pt-wcs))
(setq coords (coordsToPoints (vlax-get poly "coordinates")))
(cond
;;Test if pt on polyline
((equal closest pt-wcs 1e-10)
(verbose "\nPoint is on polyline (not inside). ")
nil
)
;;Test if polyline is not closed
;;sometimes polyline may actually be closed but not marked as closed.
((and
(equal :vlax-false (vla-get-closed poly))
(not (equal (car coords) (last coords)))
)
(verbose "\nPolyline is not closed. Can't be inside. ")
nil
)
((null (setq intersections
(getvalidintersectionswithray
pt-wcs poly attempts coords )))
(verbose "\nNo intersections. Point is outside polyline." )
nil
)
((= intersections "Search failed")
(verbose "\nSearch was inconclusive. Set attempts higher.")
nil
)
((zerop (rem (length intersections) 6))
(verbose "\nEven number of intersections: Point is outside."
)
nil
)
((verbose "\nOdd number of intersections: Point is inside.")
;;Odd number of intersections
t
)
)
)

(princ "\nPtInsidePoly by D. C. Broad. Use TEST to verify action.")
(princ)


Doug Broad

unread,
Sep 11, 2003, 9:29:40 AM9/11/03
to
Thanks Joel.

I thought Tony was actually speaking of the bpoly function. I believe bpoly
might accept the same kind of input as the boundary command but
since it is undocumented, its like shooting in the dark trying to get
it to work. A function that returns an ename would be more convenient
than the command which always returns nil.

From what Marco said and from a bit of testing, it appears that (bpoly pt)
only works with what is visible on the display and may use the display list
rather than the true geometry of the figure. So arcs are actually display listed
as polygonal shapes and the accuracy is dependent on viewres settings and
zoom factors and regens.

Regards,
Doug


"Joel Roderick" <jroderick at caddevelopmentgroup dot com> wrote in message
news:5BC76842F4AEAFBF...@in.WebX.maYIadrTaRb...

Luis Esquivel

unread,
Sep 11, 2003, 10:11:51 AM9/11/03
to
and before was call it (C:BPOLY ...same args)

for the presicion I do not have any problems yet... then also a workaround
for that could be a selection of what is in the current view and if we need
to regenerate the objects (apply 'entupd ... will do it easier before
running our function, also a think I like better by using bpoly is that we
do not rely on just a boundary made by a polyline it can be lines and arcs
too.

I don't know but again if we want to have a function that is relying on the
creation of a temporary object, then this approach will suffice.

just my poor opinion, luis.

"Luis Esquivel" <www.draftteam.com> wrote in message

news:E73A4AB335B881AC...@in.WebX.maYIadrTaRb...


> > Tony,
> > Thanks for that info. Where is bpoly documented?
> > There is no documentation in the help files.
>

> It is in my R12 documents, that I still have in my werehouse.


>
>
> (bpoly <internal-point> [optional <sel-set>] [optional <ray-cast>])
>

> also it will be very easy to make a loop using (bherrs) and have a list of
> vectors in case bpoly produces and error, also we can change the
coordinates
> precision too.
>
> Luis.
>
>
>
> >

Doug Broad

unread,
Sep 10, 2003, 9:16:47 PM9/10/03
to
Hi Luis,

I guess it depends on the application and the drawing. In
some previous threads, it was mentioned that bpoly causes
problems with large drawings.

John's program and mine were an attempt to determine
programmatically whether a point was inside a given figure.

Bpoly could be used to prove that a point is inside something
or that a valid hatch boundary exists. I don't see how it could
be used to prove whether a point was inside a given polygon
unless all the other objects were temporarily erased so that bpoly
was working only with that polyline.

Thanks for bringing up bpoly because it certainly has applications.

Regards,
Doug


"Luis Esquivel" <www.draftteam.com> wrote in message

news:2B6627471581EB68...@in.WebX.maYIadrTaRb...
> Doug,
>
> Since we are erasing tempo object then, why we do not use this:
>
> (defun isInside (pt / ename)
> (if (setq ename (bpoly pt))
> (progn
> (entdel ename)
> (princ "\nINSIDE.")))
> (princ))
>
> (defun c:tst ()
> (while (setq pt (getpoint "\nPoint: "))
> (isInside pt)))
>
> Luis.


>
> "Doug Broad" <dbr...@earthlink.net> wrote in message

> news:73F7D666956CB556...@in.WebX.maYIadrTaRb...
> > Hi Joe,
> >

<snip>


Joel Roderick

unread,
Sep 11, 2003, 10:08:26 AM9/11/03
to
Sure 'nuff your right Doug. Now why in the world would this be
undocumented? I agree that it probably does work with the display list.


"Doug Broad" <dbr...@nash.cc.nc.us> wrote in message

news:6D1BC1DCD672603E...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Sep 11, 2003, 7:26:35 AM9/11/03
to

Marc'Antonio Alessi

unread,
Sep 11, 2003, 3:23:55 AM9/11/03
to
Louis,

I had already tried bpoly/bhatch approach but the precision
is about 0.1 if the point is near the polyline.


on straight polylines we have more precision,
about 0.00001 - depend on zoom factor/regen (vmax),
with:

(pt1...ptn = polyline vertex)

(setvar "pdmode" 0)
(command
"point" pt
"select" "cp" pt1...ptn ""
)

if point is member of ss > inside


Cheers.

Marco

Doug Broad

unread,
Sep 11, 2003, 2:33:39 PM9/11/03
to
I've got it. From the R12 AutoLISP manual:
(bpoly pt [ss] [vector])

My example:
(bpoly (getpoint) (ssget) '(1 0 0))


"Luis Esquivel" <www.draftteam.com> wrote in message

news:084C4D19D75CBEB8...@in.WebX.maYIadrTaRb...
> Well I found one of my old posts and I have a different usage there, please
> try with this.
>
> (bpoly pt [ray-casting] [ss])
>
>


Luis Esquivel

unread,
Sep 10, 2003, 6:21:48 PM9/10/03
to
Doug,

Since we are erasing tempo object then, why we do not use this:

(defun isInside (pt / ename)
(if (setq ename (bpoly pt))
(progn
(entdel ename)
(princ "\nINSIDE.")))
(princ))

(defun c:tst ()
(while (setq pt (getpoint "\nPoint: "))
(isInside pt)))

Luis.

"Doug Broad" <dbr...@earthlink.net> wrote in message


news:73F7D666956CB556...@in.WebX.maYIadrTaRb...
> Hi Joe,
>
> Thanks for that information. I provided the first direction at 0.0 angle
> so that it would be easy for you guys to set up a trap for the logic. If
> I had used the random direction as the first direction then we couldn't
> discuss the problems. Glad it worked.
>
> Apparently the 1,1 vertex of your polyline has an x value of
> 0.99999999999555 or something like that and vl-position does
> not compare properly in some strange situtations like that.
>
> I substitutes vl-position with a custom subroutine, ptmember.
> It seems to work. Thanks for spotting that.
>
> It may be wise to use 3 random ray directions and have the
> algorithm continue until the "vote" is either unanimous or
> overwhelming. ;-)
>
> Get Random-Reini from previous post.
>
>

> Regards,
> Doug
>
> "Joe Burke" <job...@hawaii.rr.com> wrote in message

> news:3AC68574BED4B0FE...@in.WebX.maYIadrTaRb...


----------------------------------------------------------------------------

Joe Burke

unread,
Sep 11, 2003, 3:12:37 PM9/11/03
to
Doug & Luis,

Yup, that works. Both ss and vector must be supplied.

Joe

"Doug Broad" <dbr...@nash.cc.nc.us> wrote in message

news:328FF749A590F700...@in.WebX.maYIadrTaRb...

Tony Tanzillo

unread,
Sep 11, 2003, 12:34:33 AM9/11/03
to
BPOLY/Boundary can work with a selection set as well as
the default (everything visible in the viewport).

--
AcadXTabs: Document Tabs for AutoCAD
http://www.acadxtabs.com


"Doug Broad" <dbr...@earthlink.net> wrote in message news:A66C04358A7912E0...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Sep 9, 2003, 11:41:53 PM9/9/03
to
Hi John,

Sorry, but, con<whatever> doesn't mean anything to me. If you are refering to
a figure that is self-intersecting (where one segment runs overlapping another
segment), it would make sense to me that if a ray passed over the overlapping
parts, that it would return 1 intersection. The function that I posted won't work
with
such self intersecting polylines.

In my mind, however, such self-intersecting figures, really have no compelling
inside.
They are like Klein Bottles, which have no volume yet they occupy space or Mobius
strips, which have no ending or beginning and an ambiguous sense of inside vs outside

Another approach entirely would need to be used to identify such figures and
eliminate
them from consideration or to qualify what it means to be "inside" such a figure.

Good to hear back from you. Have a nice evening.. zz..zzzzzz ;-)

"John Uhden" <juh...@cadlantic.com> wrote in message

news:3A0364B4CCC9FCC9...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Sep 9, 2003, 2:53:12 PM9/9/03
to
Luis,
You were really close. As best as I can figure, you
made one mistake. Instead of looping to send the
ray/line in a different direction, the program appears
to eliminate the offending intersection from the count.

Am I right? Thats just a guess. I didn't follow everything
in the code.

"Luis Esquivel" <www.draftteam.com> wrote in message

news:08E4F228C1A9B028...@in.WebX.maYIadrTaRb...
> Great... :-(
>
>
<snip>


Joe Burke

unread,
Sep 11, 2003, 3:43:57 PM9/11/03
to
Doug,

Thanks for the info.

Note "invalid option keyword", though this doesn't prevent it from working.

Command: !ename
nil
Command: (setq ename (bpoly pt ss '(1 0 0)))
Invalid option keyword.
<Entity name: 400fae70>
Command: !ename
<Entity name: 400fae70>

Joe


"Doug Broad" <dbr...@nash.cc.nc.us> wrote in message

news:50D792665623398B...@in.WebX.maYIadrTaRb...
> Joe and all,
> I would also like to correct an earlier incorrect statement
> I made about the bpoly function.
> 1. The selection set of objects does not have to be displayed.
> 2. The viewres setting and regen does not appear to have an
> effect. A circle being interpreted, for instance as a polygon
> was not a problem in my test.
> 3. I would defer to Marco for his accuracy statements. I have
> not tested those.


>
>
> "Joe Burke" <job...@hawaii.rr.com> wrote in message

> news:DDC12314989D8F87...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Sep 10, 2003, 3:32:29 PM9/10/03
to
Aha,
The joke went right over my head. ;-)

"R. Robert Bell" <NOT.r...@acadx.com> wrote in message
news:A73DD4F33166AA3E...@in.WebX.maYIadrTaRb...

Luis Esquivel

unread,
Sep 11, 2003, 9:54:07 AM9/11/03
to
> Tony,
> Thanks for that info. Where is bpoly documented?
> There is no documentation in the help files.

It is in my R12 documents, that I still have in my werehouse.


(bpoly <internal-point> [optional <sel-set>] [optional <ray-cast>])

also it will be very easy to make a loop using (bherrs) and have a list of
vectors in case bpoly produces and error, also we can change the coordinates
precision too.

Luis.

>

Doug Broad

unread,
Sep 11, 2003, 3:25:32 PM9/11/03
to
Joe and all,
I would also like to correct an earlier incorrect statement
I made about the bpoly function.
1. The selection set of objects does not have to be displayed.
2. The viewres setting and regen does not appear to have an
effect. A circle being interpreted, for instance as a polygon
was not a problem in my test.
3. I would defer to Marco for his accuracy statements. I have
not tested those.

"Joe Burke" <job...@hawaii.rr.com> wrote in message

news:DDC12314989D8F87...@in.WebX.maYIadrTaRb...

Luis Esquivel

unread,
Sep 11, 2003, 2:12:12 PM9/11/03
to

Joe Burke

unread,
Sep 11, 2003, 4:01:30 PM9/11/03
to
Oh! [point] [vector] [ss]

Command: (setq ename nil)
nil
Command: (setq ename (bpoly pt '(1 0 0) ss))
<Entity name: 400faec8>
Command: !ename
<Entity name: 400faec8>

Joe

Marc'Antonio Alessi

unread,
Sep 12, 2003, 4:33:06 AM9/12/03
to
"Joe Burke" <job...@hawaii.rr.com> ha scritto nel messaggio
news:BC6E0B2A3AE877D6...@in.WebX.maYIadrTaRb...

> Oh! [point] [vector] [ss]
>
> Command: (setq ename nil)
> nil
> Command: (setq ename (bpoly pt '(1 0 0) ss))
> <Entity name: 400faec8>
> Command: !ename
> <Entity name: 400faec8>
>
> Joe
>
>

Note: [vector] can be 2D or 3D but if 3D Z is ignored

Marco

Marc'Antonio Alessi

unread,
Sep 12, 2003, 4:22:53 AM9/12/03
to
"Tony Tanzillo" <tony.tanzillo at caddzone dot com> ha scritto nel messaggio
news:46B35F2AE23D0D82...@in.WebX.maYIadrTaRb...

> "Doug Broad" <dbr...@nash.cc.nc.us> wrote in message
news:6D1BC1DCD672603E...@in.WebX.maYIadrTaRb...

> >
> > From what Marco said and from a bit of testing, it appears that (bpoly
pt)
> > only works with what is visible on the display and may use the display
list
> > rather than the true geometry of the figure. So arcs are actually
display listed
> > as polygonal shapes and the accuracy is dependent on viewres settings
and
> > zoom factors and regens.
>
>
> Not at all. BPOLY/Boundary simply selects everything visible
> in the viewport if no boundary set is specified, and uses that
> as the boundary set. But in all cases, it works with actual
> drawing entities, not with the display list. Neither Viewres or
> any other view parameter has any effect on the accuracy of
> the containment test.

>
> --
> AcadXTabs: Document Tabs for AutoCAD
> http://www.acadxtabs.com
>
>

I am surprised of to have been badly interpreted:

(in new empty dwg)
Comando: _pline
Specificare punto iniziale: 0,0
La larghezza corrente della linea è 0.0000
Specificare punto successivo o
[Arco/Mezza-larghezza/LUnghezza/ANnulla/LArghezza]: 100,0
Specificare punto successivo o
[Arco/CHiudi/Mezza-larghezza/LUnghezza/ANnulla/LArghezza]: 100,50
Specificare punto successivo o
[Arco/CHiudi/Mezza-larghezza/LUnghezza/ANnulla/LArghezza]: 0,50
Specificare punto successivo o
[Arco/CHiudi/Mezza-larghezza/LUnghezza/ANnulla/LArghezza]: _c
Comando: _zoom
Specificare un angolo della finestra, digitare un fattore di scala (nX o
nXP) o
[Tutto/Centrato/Dinamico/Estensioni/Precedente/scAla/Finestra] <tempo
reale>: _e

(setq ss (ssadd (entlast)))

Comando: (bpoly '(50 25) '(1 0 0) ss)
<Nome entità: 402cbf00>

Comando: (bpoly '(0.1 0.1) '(1 0 0) ss)
<Nome entità: 402cbed8>

Selezionare oggetti:
Comando: (bpoly '(0.01 0.01) '(1 0 0) ss)

Il punto è direttamente su un oggetto.nil <<<<<<<<<
English: point is directly on a object <<<<<<<<<


--

Thanks to all to have answered directly me
and not to have ignored the part related to

"select" "cp" on straight polylines

Cheers.

Marco

"Marc'Antonio Alessi" <maalessi at tin dot it> ha scritto nel messaggio
news:41D94615651E1CEA...@in.WebX.maYIadrTaRb...

Joe Burke

unread,
Sep 11, 2003, 1:40:52 PM9/11/03
to
Hi Luis,

> (bpoly <internal-point> [optional <sel-set>] [optional <ray-cast>])

Using A2k2. I can't get the optional arguments to work. Returns nil.

(bpoly pt ss)
or
(bpoly pt ss t)

Where ss is selection set containing a single closed lwpolyline.

Joe


Marc'Antonio Alessi

unread,
Sep 12, 2003, 4:24:06 AM9/12/03
to
> 3. I would defer to Marco for his accuracy statements. I have
> not tested those.

See my reply to Tony.

Cheers.

Marco

Doug Broad

unread,
Sep 12, 2003, 8:01:12 AM9/12/03
to
Marco,
Thanks for the correction and clarification. I had
completely missed that you were proposing a different
technique other than bpoly for determining whether a point
was inside a polyline having only straight sides. Sorry.

Thanks for the example showing the type of inaccuracy
mentioned.

Regards,
Doug


"Marc'Antonio Alessi" <maalessi at tin dot it> wrote in message
news:6C464C1DDE1775BF...@in.WebX.maYIadrTaRb...

Tony Tanzillo

unread,
Sep 11, 2003, 11:40:01 PM9/11/03
to
"Doug Broad" <dbr...@nash.cc.nc.us> wrote in message news:6D1BC1DCD672603E...@in.WebX.maYIadrTaRb...
>
> From what Marco said and from a bit of testing, it appears that (bpoly pt)
> only works with what is visible on the display and may use the display list
> rather than the true geometry of the figure. So arcs are actually display listed
> as polygonal shapes and the accuracy is dependent on viewres settings and
> zoom factors and regens.

Not at all. BPOLY/Boundary simply selects everything visible
in the viewport if no boundary set is specified, and uses that
as the boundary set. But in all cases, it works with actual
drawing entities, not with the display list. Neither Viewres or
any other view parameter has any effect on the accuracy of
the containment test.

--

Tony Tanzillo

unread,
Sep 12, 2003, 2:31:11 PM9/12/03
to
Another way of testing containment is to use the
OFFSET command with the 'Through point' option.

If the resulting offset entity has a length or
area smaller than the original, the test point
is inside.

--
AcadXTabs: Document Tabs for AutoCAD
http://www.acadxtabs.com


"Joe Burke" <job...@hawaii.rr.com> wrote in message news:1F4D1736C0529CF1...@in.WebX.maYIadrTaRb...
> Doug and all,
>
> More testing... Actually bpoly ignores the selection set when the arguments are
> in this order:
>
> (bpoly pt 2dvector ss)
>
> But then it doesn't report an error: Invalid option keyword.
>
> Reverse the arguments:
>
> (bpoly pt ss 2dvector)
>
> Error, but the selection set is honored and the function works.
>
> Testing with a rectangle and a circle which partly intersects the rectangle. The
> point is in the area where the two intersect. The selection set contains only
> the rectangle. The boundary created in the first case (vector ss) is the
> intersection area. Given (ss vector) the boundary created is the rectangle.
> Please confirm.
>
> I trust we'll get it right eventually. :-)
>
> Joe


>
>
> "Doug Broad" <dbr...@nash.cc.nc.us> wrote in message

> news:0C238E133B9CD69B...@in.WebX.maYIadrTaRb...
> > Tony,
> > Thanks for your clarification. I agree that in no case
> > does Bpoly use the display list.
> >
> > Also, if you look at some of the earlier posts by Joe, Luis and myself,
> > you will note that the bpoly lisp function won't ignore the selection
> > set if given in the order:
> >
> > (bpoly pt 2dvector ss)
> >
> > Example:
> >
> > (bpoly (getpoint) '(1 0) (ssget))
> >
> >
> >
> > "Tony Tanzillo" <tony.tanzillo at caddzone dot com> wrote in message
> > news:13BC89E3A4D7F684...@in.WebX.maYIadrTaRb...
> > >
> > > Under no case does BPOLY do what Doug suggested (use
> > > display list geometry rather than drawing objects).
> > >
> > > Also, I was referring to BOUNDARY (the command) (the bpoly
> > > LISP function is just a wrapper around it, and appears to
> > > ignore the selection set).
> > >
> > > --
> > <snip>
> >
> >
>
>


Doug Broad

unread,
Sep 12, 2003, 11:50:04 AM9/12/03
to

Joe Burke

unread,
Sep 12, 2003, 4:01:24 PM9/12/03
to
Doug,

Agreed regarding bpoly. IMO your function is the best solution.

Joe

"Doug Broad" <dbr...@earthlink.net> wrote in message

news:850136374975D6B6...@in.WebX.maYIadrTaRb...
> Thanks Joe,
>
> Guess I was wrong again. :-(
>
> Well I don't think I want to use a function that either accepts the
> selection set but reports an error or ignores the selection altogether.
> Guess that is why it remains quietly undocumented in the current
> version.
>
> Guess we're back to
> (command "boundary" "a" "b" .....) or something like Marco
> posted for straight polylines or something like I posted for
> the polylines containing arc segments.
>
> I think I've gotten all I can from this thread. Thanks to all.
> Have a nice weekend.
>
> Regards,
> Doug


>
>
> "Joe Burke" <job...@hawaii.rr.com> wrote in message
> news:1F4D1736C0529CF1...@in.WebX.maYIadrTaRb...
> > Doug and all,
> >
> > More testing... Actually bpoly ignores the selection set when the arguments
are

> > in this order:
> >
> > (bpoly pt 2dvector ss)
> >


> > But then it doesn't report an error: Invalid option keyword.
> >
> > Reverse the arguments:
> >
> > (bpoly pt ss 2dvector)
> >
> > Error, but the selection set is honored and the function works.
> >
> > Testing with a rectangle and a circle which partly intersects the rectangle.
The
> > point is in the area where the two intersect. The selection set contains
only
> > the rectangle. The boundary created in the first case (vector ss) is the
> > intersection area. Given (ss vector) the boundary created is the rectangle.
> > Please confirm.
> >
> > I trust we'll get it right eventually. :-)
> >
> > Joe
> >

> <snip>
>
>


Tony Tanzillo

unread,
Sep 12, 2003, 11:40:01 AM9/12/03
to
"Marc'Antonio Alessi" <maalessi at tin dot it> wrote in message

> I am surprised of to have been badly interpreted:

You weren't badly interepreted.

Under no case does BPOLY do what Doug suggested (use
display list geometry rather than drawing objects).

Also, I was referring to BOUNDARY (the command) (the bpoly
LISP function is just a wrapper around it, and appears to
ignore the selection set).

--

AcadXTabs: Document Tabs for AutoCAD
http://www.acadxtabs.com


news:6C464C1DDE1775BF...@in.WebX.maYIadrTaRb...


> "Tony Tanzillo" <tony.tanzillo at caddzone dot com> ha scritto nel messaggio
> news:46B35F2AE23D0D82...@in.WebX.maYIadrTaRb...
> > "Doug Broad" <dbr...@nash.cc.nc.us> wrote in message
> news:6D1BC1DCD672603E...@in.WebX.maYIadrTaRb...
> > >
> > > From what Marco said and from a bit of testing, it appears that (bpoly
> pt)
> > > only works with what is visible on the display and may use the display
> list
> > > rather than the true geometry of the figure. So arcs are actually
> display listed
> > > as polygonal shapes and the accuracy is dependent on viewres settings
> and
> > > zoom factors and regens.
> >
> >
> > Not at all. BPOLY/Boundary simply selects everything visible
> > in the viewport if no boundary set is specified, and uses that
> > as the boundary set. But in all cases, it works with actual
> > drawing entities, not with the display list. Neither Viewres or
> > any other view parameter has any effect on the accuracy of
> > the containment test.
> >
> > --
> > AcadXTabs: Document Tabs for AutoCAD
> > http://www.acadxtabs.com
> >
> >
>
>

Doug Broad

unread,
Sep 12, 2003, 3:03:59 PM9/12/03
to
Thanks Joe,

Guess I was wrong again. :-(

Well I don't think I want to use a function that either accepts the
selection set but reports an error or ignores the selection altogether.
Guess that is why it remains quietly undocumented in the current
version.

Guess we're back to
(command "boundary" "a" "b" .....) or something like Marco
posted for straight polylines or something like I posted for
the polylines containing arc segments.

I think I've gotten all I can from this thread. Thanks to all.
Have a nice weekend.

Regards,
Doug


"Joe Burke" <job...@hawaii.rr.com> wrote in message
news:1F4D1736C0529CF1...@in.WebX.maYIadrTaRb...
> Doug and all,
>
> More testing... Actually bpoly ignores the selection set when the arguments are

> in this order:
>
> (bpoly pt 2dvector ss)
>

Marc'Antonio Alessi

unread,
Sep 12, 2003, 1:35:01 PM9/12/03
to
"Tony Tanzillo" <tony.tanzillo at caddzone dot com> ha scritto nel messaggio
>
> Under no case does BPOLY do what Doug suggested (use
> display list geometry rather than drawing objects).
>

hmmm... maybe we are beating about the bush:

command: pline 0.0 100,0 100,50 0,50 c
command: (setq ss (ssadd (entlast)))
<Selection set: 2>
command: zoom e
command: (bpoly '(0.01 0.01) '(1 0 0) ss)


point is directly on a object <<<<<<<<<

command: zoom 0,0 1,1
command: (bpoly '(0.01 0.01) '(1 0 0) ss)
<Nome entità: 40078db0> <<<<<<<<<

I think it depend by zoom factor, I can not pass a point near the entity.
I agree about the fact that the boundary is computed with drawing objects
rather display list geometry.


> Also, I was referring to BOUNDARY (the command) (the bpoly
> LISP function is just a wrapper around it, and appears to
> ignore the selection set).
>

why do you say this if I have shown to you hardly that it is not true?


Cheers.

Marco

Doug Broad

unread,
Sep 10, 2003, 6:10:54 PM9/10/03
to
Hi Joe,

Thanks for that information. I provided the first direction at 0.0 angle
so that it would be easy for you guys to set up a trap for the logic. If
I had used the random direction as the first direction then we couldn't
discuss the problems. Glad it worked.

Apparently the 1,1 vertex of your polyline has an x value of
0.99999999999555 or something like that and vl-position does
not compare properly in some strange situtations like that.

I substitutes vl-position with a custom subroutine, ptmember.
It seems to work. Thanks for spotting that.

It may be wise to use 3 random ray directions and have the
algorithm continue until the "vote" is either unanimous or
overwhelming. ;-)

Get Random-Reini from previous post.


Regards,
Doug

"Joe Burke" <job...@hawaii.rr.com> wrote in message

news:3AC68574BED4B0FE...@in.WebX.maYIadrTaRb...
> Doug,
>
> Example file in CF. Really curious...
>

> Joe
>
>
> "Doug Broad" <dbr...@earthlink.net> wrote in message

> news:014F85692B9D430E...@in.WebX.maYIadrTaRb...
> > Hi Joe,
> > Just tested it about 200 times and didn't get a single error.
> > I can't explain why you might be getting different results.
> > Anyone else?
> >

> > Regards,
> > Doug
> >
> > "Joe Burke" <job...@hawaii.rr.com> wrote in message

> > news:1CFA71CD57FFCA2A...@in.WebX.maYIadrTaRb...
> > > Doug,
> > >
> > > Right. My mistake, I meant test point at -1,1.
> > >
> > > I've run numerous tests. Sometimes it works right, other times not, using
> the
> > > same shape mentioned previously. Always with test point at -1,1 *relative*
> to
> > > the lower left vertex of the pline. I say relative to because if I copy the
> > > pline to various locations, it works at some locations. Strange, I can't see
> any
> > > pattern in the behavior.
> > >
> > > I re-downloaded your post. Made this change:
> > >
> > > > (defun GetValidIntersectionsWithRay (pt-wcs .......
> > >
> > > And commented out: (vla-delete ray)
> > >
> > > I'll post an example file to CF.
> > >
> > > Thanks
> > > Joe
> > >

> > > "Doug Broad" <dbr...@nash.cc.nc.us> wrote in message

insidepoly2.lsp

Tony Tanzillo

unread,
Sep 12, 2003, 3:51:40 PM9/12/03
to
The BPOLY function is broken. See Joe's message. It reports
errors when it shouldn't. It's just making calls to the
BOUNDARY command, and so there's little point to using BPOLY
when you can use the latter, and look at the last entity in
the drawing to see if a boundary was created.

--
AcadXTabs: Document Tabs for AutoCAD
http://www.acadxtabs.com

"Marc'Antonio Alessi" <maalessi at tin dot it> wrote in message

news:593D79DFBE1C0829...@in.WebX.maYIadrTaRb...

Joe Burke

unread,
Sep 12, 2003, 2:10:18 PM9/12/03
to
Doug and all,

More testing... Actually bpoly ignores the selection set when the arguments are

in this order:

(bpoly pt 2dvector ss)

But then it doesn't report an error: Invalid option keyword.

Reverse the arguments:

(bpoly pt ss 2dvector)

Error, but the selection set is honored and the function works.

Testing with a rectangle and a circle which partly intersects the rectangle. The
point is in the area where the two intersect. The selection set contains only
the rectangle. The boundary created in the first case (vector ss) is the
intersection area. Given (ss vector) the boundary created is the rectangle.
Please confirm.

I trust we'll get it right eventually. :-)

Joe


"Doug Broad" <dbr...@nash.cc.nc.us> wrote in message

news:0C238E133B9CD69B...@in.WebX.maYIadrTaRb...

0 new messages