Author Topic: (Challenge) Find the triangle within a TIN that contains a given point.  (Read 5362 times)

0 Members and 1 Guest are viewing this topic.

FengK

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





Arch_Eric

  • Guest
Do you want to select the triangle or do you want a list of points or what?

FengK

  • Guest
Do you want to select the triangle or do you want a list of points or what?

A list of three points.

uncoolperson

  • Guest
edit: need to debug better
« Last Edit: June 20, 2008, 03:25:29 PM by uncoolperson »

Arch_Eric

  • Guest
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...
« Last Edit: June 20, 2008, 03:15:47 PM by Arch_Eric »

FengK

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

DEVITG

  • Bull Frog
  • Posts: 480
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

 
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Just a language fact, why this is a TIN , what does it mean ?
Triangulated Irregular Network

DEVITG

  • Bull Frog
  • Posts: 480
Hi , thanks.


Gabriel
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Spike Wilbury

  • Guest
you can use the function bpoly:

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

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


hth

Arch_Eric

  • Guest
Nifty. Didn't know about that function. Its not in my AutoLISP Reference  :-(  Though it is the 2000 version. I need some updated materials.

FengK

  • Guest
Thanks Luis. I wasn't aware of this one either. Maybe it is from Express Tools?

Alan Cullen

  • Guest
bpoly is an acad command shortcut for BOUNDARY.

Arch_Eric

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

SomeCallMeDave

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