Find for nearest object?

Find for nearest object?

Anonymous
Not applicable
1,064 Views
5 Replies
Message 1 of 6

Find for nearest object?

Anonymous
Not applicable
Hi,
does anyone know an easy way to find the nearest line to a point. The way I have been doing this is creating a selection set of lines and looping thru the lines, checking the distances and if the distance is shorter than the last hold that one. I was kinda looking from a less eloborate way to find this. Thanks
0 Likes
1,065 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
http://www.ping.be/math/recht.htm
0 Likes
Message 3 of 6

Anonymous
Not applicable
Thanks for reply, but I know how to find the distance between a point and a line. I was just looking for a simpler way to find the closest line to a point.
0 Likes
Message 4 of 6

Anonymous
Not applicable
Don't know if this helps but...

 

I did somthing similar but decided that I wanted to
loop through the smallest sset poosible so starting from the point that I
picked, I created a selection set with a crossing window that began one unit
below and to the left and ended one unit to the right and above. If something
was found, check the distance on the entites (unless only one was found). If
nothing was found, add one more unit to each of the points. Keep repeating until
results is found or offset reaches a preset number (a max distance value). Why
am I blabbering?? Here is the code, see if it helps....

 

Public Function FindNearestEntity(ByVal Point1 As
Variant, ByVal MaxDistance As Double, Optional LayerPattern As String = "*") As
AcadEntity
  Dim sst_items As AcadSelectionSet
  Dim ent_retrn
As AcadEntity
  Dim dbl_offst As Double
  Dim pnt_lleft(2) As
Double
  Dim pnt_urght(2) As Double
  Dim dxf_codes(7) As
Integer
  Dim dxf_value(7) As Variant
  Dim dbl_prevs As
Double
  Dim dbl_distn As Double
  Dim pnt_nears As
Variant
  Dim ent_check As AcadEntity
 
  dxf_codes(0)
= 8
  dxf_value(0) = LayerPattern
  dxf_codes(1) = -4
 
dxf_value(1) = "<OR"
  dxf_codes(2) = 0
  dxf_value(2) =
"LINE"
  dxf_codes(3) = 0
  dxf_value(3) = "CIRCLE"
 
dxf_codes(4) = 0
  dxf_value(4) = "ARC"
  dxf_codes(5) =
0
  dxf_value(5) = "POLYLINE"
  dxf_codes(6) = 0
 
dxf_value(6) = "LWPOLYLINE"
  dxf_codes(7) = -4
  dxf_value(7) =
"OR>"
  dbl_offst = 2

 

 On Local Error Resume Next
 
ThisDrawing.SelectionSets("FindNearest").Delete
  Set sst_items =
ThisDrawing.SelectionSets.Add("FindNearest")
 On Local Error GoTo
0
 
  Do While dbl_offst < MaxDistance
   
pnt_lleft(0) = Point1(0) - dbl_offst
    pnt_lleft(1) =
Point1(1) - dbl_offst
    pnt_urght(0) = Point1(0) +
dbl_offst
    pnt_urght(1) = Point1(1) +
dbl_offst
  
    sst_items.Select
acSelectionSetCrossing, pnt_lleft, pnt_urght, dxf_codes,
dxf_value
    If sst_items.Count = 1
Then
      Set ent_retrn =
sst_items.Item(0)
      Exit
Do
    ElseIf sst_items.Count > 0
Then
      'process each entity to see which one is
actually closer....
      For Each ent_check In
sst_items
        pnt_nears =
tjnLSP.ClosestPointTo(ent_check, Point1,
False)
        If Not
tjnARR.ArrayIsEmpty(pnt_nears)
Then
          dbl_distn =
tjnCAL.Distance(Point1,
pnt_nears)
          If
dbl_prevs = 0
Then
            Set
ent_retrn =
ent_check
           
dbl_prevs = dbl_distn
         
ElseIf dbl_distn < dbl_prevs
Then
            Set
ent_retrn =
ent_check
           
dbl_prevs = dbl_distn
         
End If
        End
If
        pnt_nears =
Empty
      Next
     
Exit Do
    End If
    dbl_offst = dbl_offst
+ 2
  Loop
  Set FindNearestEntity = ent_retrn
End
Function


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Thanks
for reply, but I know how to find the distance between a point and a line. I
was just looking for a simpler way to find the closest line to a
point.
0 Likes
Message 5 of 6

Anonymous
Not applicable
Hi Dan,

Your first idea is as good as you can get. You can't expect the computer to
provide an answer without investigating every line in the set.

However, you may be able to limit the lines to investigate by creating your
selection set of lines using a crossing window.

--


Laurie Comerford
CADApps
www.cadapps.com.au


"dan01" wrote in message
news:f1a35be.1@WebX.maYIadrTaRb...
> Thanks for reply, but I know how to find the distance between a point and
a line. I was just looking for a simpler way to find the closest line to a
point.
0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks you all for the help.
0 Likes