TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: FengK on June 20, 2008, 01:43:51 PM

Title: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: FengK on June 20, 2008, 01:43:51 PM
Please see attached image.

Given a TIN, and a point picked by user. How to find the triangle (three points) that contains the point? The result might be multiple triangles if the point is on one of the TIN lines. In this case, return any one of the triangles is ok.

No need to post code. Just the description of steps. I can think of an (very) ugly approach:   :oops:

1. Start with a small polygon (6-sided or 8-sided) whose center if the point picked by user, make a CP selectionset using the polygon to see if it contains any of the TIN lines; if yes, go to step 2; if no, increase the polygon size, check again. Repeat until at least one TIN lines is selected;
2. Find the TIN line that is the closest to the polygon center. By "closest", I mean the perpendicular distance between the polygon center and the TIN line is the smallest;
3. At each end (Point A and B) of the TIN line (found in step 2), make a CP selectionset of TIN lines using a very small polygon; then find one TIN line from each of these two selectionsets that shares a common vertex (Point C).

Point A, B and C would be the triangle (or one of the triangles) that contains the point.

Thanks.




Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: Arch_Eric on June 20, 2008, 02:09:31 PM
Do you want to select the triangle or do you want a list of points or what?
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: FengK on June 20, 2008, 02:19:41 PM
Do you want to select the triangle or do you want a list of points or what?

A list of three points.
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: uncoolperson on June 20, 2008, 03:09:31 PM
edit: need to debug better
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: Arch_Eric on June 20, 2008, 03:10:14 PM
For now...

Code: [Select]
(defun c:getTIN ( / cmdecho inside-point bound)
 (setq cmdecho (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (setq inside-point (getpoint "\nSelect inside point: "))
 (if (not (= 'LIST(type inside-point))) (exit))
 (command "-boundary" inside-point "")
 (setq bound (vlax-ename->vla-object (entlast)))
 (setq pt-list (vlax-get bound 'Coordinates))
 (entdel (entlast))
 (princ "\n")(princ pt-list)
 (setvar "cmdecho" cmdecho)
 (princ)
)

I'd have to put in some kind of check to see if the point were on a line. The above works for points inside a triangle. And the points are stored in pt-list

EDIT: Found the command I was looking for...
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: FengK on June 21, 2008, 04:19:44 AM
Thanks Eric! This seems to be a much simpler solution. How come I didn't think of using the command -BOUNDARY? I guess I'll need to use the Advanced Option of it so that it only selects LINEs from the TIN layer.
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: DEVITG on June 28, 2008, 09:01:53 AM
Just a language fact, why this is a TIN , what does it mean ?

 Of course I'm not a English spoken person.

   Tin for me is a kind of vegetable conserver package, the like from where  Popeye take the spinach, and an  element metal allied with Lead to make solder. "Tin is a chemical element with the symbol Sn " form Wikipedia.

Tanks in advance

 
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: VovKa on June 28, 2008, 09:15:30 AM
Just a language fact, why this is a TIN , what does it mean ?
Triangulated Irregular Network
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: DEVITG on June 28, 2008, 11:54:51 AM
Hi , thanks.


Gabriel
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: Spike Wilbury on July 10, 2008, 07:03:50 PM
you can use the function bpoly:

(if (setq ename (bpoly (getpoint "\nInternal point: ")))

here... do something with the ename...


hth
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: Arch_Eric on July 10, 2008, 08:35:20 PM
Nifty. Didn't know about that function. Its not in my AutoLISP Reference  :-(  Though it is the 2000 version. I need some updated materials.
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: FengK on July 10, 2008, 08:56:18 PM
Thanks Luis. I wasn't aware of this one either. Maybe it is from Express Tools?
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: Alan Cullen on July 10, 2008, 09:05:50 PM
bpoly is an acad command shortcut for BOUNDARY.
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: Arch_Eric on July 10, 2008, 09:45:09 PM
Right, but normally you would have to call (command "bpoly") or the vl equivalent to use the Autocad command, which would require entlast to get the resulting boundary. Luis was pointing out the LISP equivalent by calling (bpoly (getpoint)) which returns the ename of the resulting boundary.
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: SomeCallMeDave on July 10, 2008, 09:49:33 PM
Has anyone tried the bpoly/boundary solution? 

I always thought  that the enclosing segments had to be planar for bpoly to work.  If that is the case, it is very unlikely that the TIN  edges would be planar.
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: Spike Wilbury on July 10, 2008, 10:33:38 PM
Nifty. Didn't know about that function. Its not in my AutoLISP Reference  :-(  Though it is the 2000 version. I need some updated materials.

It was documented many releases ago, before it was named c:bpoly

Something like:

(bpoly pt [ss] [vector])
Title: Re: (Challenge) Find the triangle within a TIN that contains a given point.
Post by: Spike Wilbury on July 10, 2008, 10:40:37 PM
Thanks Luis. I wasn't aware of this one either. Maybe it is from Express Tools?

No, it is an old ADS app as far as I know or knew about it.... before was (C:BPOLY) and also it was included the (C:BHATCH) function and now you can use (bhatch) in autolisp, no need for the command call.