Jump to content

Comparing coordinates of two points


GreenBee

Recommended Posts

Hi,

 

I have drawn a line, an arc, and another line which make continuous object (endpoint of first line is the startpoint of an arc and endpoint of an arc is the startpoint of the second line).

 

Problem occurs when I compare coordinates of an endopoint of the previous element to the startpoint of the next element. Something like this:

 

if line1.endpoint(0)=arc1.startpoint(0) and line1.endpoint(1)=arc1.startpoint(1) then ...

end if

 

The program just skips that part of the code like the coordinates do not match. I've been busting my head with this for quite a while and can't find the solution. It becomes even more awkward because rarely it works just fine, and I haven't found the cause why it sometimes works and why in most of the cases it doesn't.

 

And what amazes me the most is when I get him to write all the startpoints and all the endpoints of all the elements, they match perfectly, to the 11th decimal place.

 

If someone knows the solution to this, I'd be most grateful. Thanks in advance

Link to comment
Share on other sites

PocToc = ThisDrawing.Utility.GetPoint(, "Odaberite pocetnu tocku trase")

ZadToc = ThisDrawing.Utility.GetPoint(, "Odaberite zadnju tocku trase")

 

For Each SOS In ThisDrawing.SelectionSets

If SOS.Name = "MySS" Then

ThisDrawing.SelectionSets("MySS").Delete

Exit For

End If

Next

 

ThisDrawing.SelectionSets.Add ("MySS")

Set objSS = ThisDrawing.SelectionSets("MySS")

objSS.SelectOnScreen

 

If objSS.Count

Link to comment
Share on other sites

For Each objent In objSS
       Select Case objent.ObjectName
       Case "AcDbLine"
           Set Pravac = objent
                L = L + Pravac.Length
If (Pravac.StartPoint(0) = PocToc(0)) And (Pravac.StartPoint(1) = PocToc(1)) Then
               PrvaTocka(0) = PocToc(0)
               PrvaTocka(1) = PocToc(1)
               PrvaTocka(2) = PocToc(2)
               DrugaTocka(0) = Pravac.EndPoint(0)
               DrugaTocka(1) = Pravac.EndPoint(1)
               DrugaTocka(2) = Pravac.EndPoint(2)
               PlusMinus = True
               End If
               If (Pravac.EndPoint(0) = PocToc(0)) And (Pravac.EndPoint(1) = PocToc(1)) Then
               PrvaTocka(0) = PocToc(0)
               PrvaTocka(1) = PocToc(1)
               PrvaTocka(2) = PocToc(2)
               DrugaTocka(0) = Pravac.StartPoint(0)
               DrugaTocka(1) = Pravac.StartPoint(1)
               DrugaTocka(2) = Pravac.StartPoint(2)
               PlusMinus = True
               End If

'<<<<<KRUZNI LUK>>>>>
       Case "AcDbArc"
           Set Luk = objent
           L = L + Luk.ArcLength
           Lluk = Luk.ArcLength
           Rluk = Luk.Radius
           PlusMinus = False
'Ako luk nije prvi element trase
   'Ako je startpoint luka jednak drugoj tocki
           If Luk.StartPoint(0) = DrugaTocka(0) And Luk.StartPoint(1) = DrugaTocka(1) Then
           PrvaTocka(0) = Luk.StartPoint(0)
           PrvaTocka(1) = Luk.StartPoint(1)
           PrvaTocka(2) = Luk.StartPoint(2)
           DrugaTocka(0) = Luk.EndPoint(0)
           DrugaTocka(1) = Luk.EndPoint(1)
           DrugaTocka(2) = Luk.EndPoint(2)
           PlusMinus = True
           n = 10
           End If
   'Ako je endpoint luka jednak drugoj tocki
           If Luk.EndPoint(0) = DrugaTocka(0) And Luk.EndPoint(1) = DrugaTocka(1) Then
           PrvaTocka(0) = Luk.EndPoint(0)
           PrvaTocka(1) = Luk.EndPoint(1)
           PrvaTocka(2) = Luk.EndPoint(2)
           DrugaTocka(0) = Luk.StartPoint(0)
           DrugaTocka(1) = Luk.StartPoint(1)
           DrugaTocka(2) = Luk.StartPoint(2)
           PlusMinus = True
           n = 12
           End If
           
           If PlusMinus = True Then
       'pocetna tocka luka
           Set linija1 = ThisDrawing.ModelSpace.AddLine(PrvaTocka, Luk.Center)
           Set Krug = ThisDrawing.ModelSpace.AddCircle(PrvaTocka, SirCest / 3.5)
           sjeciste = linija1.IntersectWith(Krug, acExtendNone)
           Krug.Delete
           linija1.Delete
           Set PopLin = ThisDrawing.ModelSpace.AddLine(PrvaTocka, sjeciste)
           PopLin.Copy
           PopLin.Move sjeciste, PrvaTocka
           Set Kruzic = ThisDrawing.ModelSpace.AddCircle(PrvaTocka, SirCest / 3.5)
       'sredisnja tocka luka
           Set linija1 = ThisDrawing.ModelSpace.AddLine(PrvaTocka, Luk.Center)
           Set linija2 = ThisDrawing.ModelSpace.AddLine(DrugaTocka, Luk.Center)
           linija1.Rotate PrvaTocka, pi / 2
           linija2.Rotate DrugaTocka, pi / 2
           sjeciste = linija1.IntersectWith(linija2, acExtendBoth)
           linija1.Delete
           linija2.Delete
           Set linija2 = ThisDrawing.ModelSpace.AddLine(sjeciste, Luk.Center)
           SredisnjaTockaLuka = linija2.IntersectWith(Luk, acExtendNone)
           linija2.Delete
           Set Krug = ThisDrawing.ModelSpace.AddCircle(SredisnjaTockaLuka, SirCest / 3.5)
           Set linija1 = ThisDrawing.ModelSpace.AddLine(SredisnjaTockaLuka, Luk.Center)
           sjeciste = linija1.IntersectWith(Krug, acExtendNone)
           Krug.Delete
           linija1.Delete
           Set PopLin = ThisDrawing.ModelSpace.AddLine(SredisnjaTockaLuka, sjeciste)
           PopLin.Copy
           PopLin.Move sjeciste, SredisnjaTockaLuka
           Set Kruzic = ThisDrawing.ModelSpace.AddCircle(SredisnjaTockaLuka, SirCest / 3.5)
'------>Ostali profili na luku
   'Ako je luk duzi od razmaka profila
           If Lluk > RazProf Then
               Alfa = (Lostatak * 180) / pi * Rluk
               ThisDrawing.Utility.Prompt Alfa & vbCrLf
               Set linija1 = ThisDrawing.ModelSpace.AddLine(Luk.Center, PrvaTocka)
               linija1.Rotate Alfa
               sjeciste2 = linija1.IntersectWith(Luk, acExtendNone)
                   If sjeciste2(0) = 0 And sjeciste2(1) = 0 Then
                       Alfa = -1 * Alfa
                       linija1.Rotate (2 * Alfa)
                       sjeciste2 = linija1.IntersectWith(Luk, acExtendNone)
                   End If
               linija1.Delete
               Set linija1 = ThisDrawing.ModelSpace.AddLine(sjeciste2, Luk.Center)
               Set Krug = ThisDrawing.ModelSpace.AddCircle(sjeciste2, SirCest / 3.5)
               sjeciste = linija1.IntersectWith(Krug, acExtendNone)
               Krug.Delete
               linija1.Delete
               Set PopLin = ThisDrawing.ModelSpace.AddLine(sjeciste2, sjeciste)
               PopLin.Copy
               PopLin.Move sjeciste, sjeciste2
               Set Kruzic = ThisDrawing.ModelSpace.AddCircle(PrvaTocka, SirCest / 3.5)
           End If
           PlusMinus = False
           End If
       End Select
   Next

Link to comment
Share on other sites

Hi,

 

I have drawn a line, an arc, and another line which make continuous object (endpoint of first line is the startpoint of an arc and endpoint of an arc is the startpoint of the second line).

 

Problem occurs when I compare coordinates of an endopoint of the previous element to the startpoint of the next element using VBA code. Something like this:

 

if line1.endpoint(0)=arc1.startpoint(0) and line1.endpoint(1)=arc1.startpoint(1) then

...

end if

 

The program just skips that part of the code like the coordinates do not match. I've been busting my head with this for quite a while and can't find the solution. It becomes even more awkward because on some occasions it works just fine, and I haven't found the cause why it sometimes works and why in most of the cases it doesn't.

 

And what amazes me the most is when I get VBA to write all the startpoints and all the endpoints of all the elements, they match perfectly, to the 11th decimal place.

 

If someone knows the solution to this, I'd be most grateful. Thanks in advance

Link to comment
Share on other sites

The problem lies in that the coordinates do not match EXACTLY, there is a very, very small difference. The coordinates you see are to a certain precision, but when values are calculated their precision is sometimes more than that displayed. Although they look the same they are not.

 

Try something that introduces a fuzzy match, something like:

 

If Abs(line1.EndPoint(0) - arc1.StartPoint(0) < 0.00001 _
And Abs(line1.EndPoint(1) - arc1.StartPoint(0) < 0.00001 Then
    The rest of your code
end If

Link to comment
Share on other sites

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