CIRCLE CIRCLE INTERSECTION

CIRCLE CIRCLE INTERSECTION

Anonymous
Not applicable
590 Views
8 Replies
Message 1 of 9

CIRCLE CIRCLE INTERSECTION

Anonymous
Not applicable
ANY WIZ KIDS OUT THERE? GIVEN X1, Y1 AND X2, Y2 AND RADIUS1 AND RADIUS2

IS THERE A SIMPLE WAY TO CALCULATE THE TWO INTERSECTIONS WITHOUT ACTUALLY DRAWING TWO CIRCLES IN AUTOCAD?
0 Likes
591 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
Don't shout, please
0 Likes
Message 3 of 9

Anonymous
Not applicable
Try this one

Public Function GetTwoCirclesInters(p1 As Variant, p2 As Variant, r1 As Double, r2 As Double) As Variant

Dim dis As Double
Dim ip1 As Variant
Dim ip2 As Variant
Dim inters(0 To 1, 0 To 2) As Double
With ThisDrawing.Utility
dis = Distance(p1, p2)
If dis > r1 + r2 Then
GetTwoCirclesInters = Null
Exit Function
ElseIf dis >= r1 + r2 + 0.000000000001 Then '<--fuzz
ip1 = .PolarPoint(p1, .AngleFromXAxis(p1, p2), r1)
ip2 = .PolarPoint(p1, .AngleFromXAxis(p1, p2), r1)
Else
Dim cosinA As Double
Dim ang As Double
cosinA = (((r1 * r1) + (dis * dis)) - (r2 * r2)) / (2# * r1 * dis)
ang = Atn((Sqr(1 - (cosinA * cosinA))) / cosinA)
ip1 = .PolarPoint(p1, .AngleFromXAxis(p1, p2) + ang, r1)
ip2 = .PolarPoint(p1, .AngleFromXAxis(p1, p2) - ang, r1)
inters(0, 0) = ip1(0): inters(0, 1) = ip1(1): inters(0, 2) = ip1(2)
inters(1, 0) = ip2(0): inters(1, 1) = ip2(1): inters(1, 2) = ip2(2)
End If
End With
GetTwoCirclesInters = inters
End Function

Function Distance(p1 As Variant, p2 As Variant) As Double
Distance = Sqr((p1(0) - p2(0)) ^ 2 + ((p1(1) - p2(1)) ^ 2))
End Function

Sub test()
Dim p1(2) As Double
Dim p2(2) As Double
Dim r1 As Double
Dim r2 As Double
p1(0) = 0#: p1(1) = 0#: p1(2) = 0#:
p2(0) = -500#: p2(1) = -500#: p2(2) = 0#

r1 = 600#: r2 = 300#
Dim inters As Variant
inters = GetTwoCirclesInters(p1, p2, r1, r2)
Dim ip1(2) As Double
Dim ip2(2) As Double
ip1(0) = inters(0, 0): ip1(1) = inters(0, 1): ip1(2) = inters(0, 2)
ip2(0) = inters(1, 0): ip2(1) = inters(1, 1): ip2(2) = inters(1, 2)
ThisDrawing.ModelSpace.AddLine ip1, ip2
End Sub

~'J'~
0 Likes
Message 4 of 9

Anonymous
Not applicable
Fatty,

msgbox "YOU ARE THE MAN"

I always had to draw two circles then then draw lines from the intersect points. I have to do this many times a day. Thank you very^100 much!

God Bless
0 Likes
Message 5 of 9

Anonymous
Not applicable
Wouldn't it be as easy as...

If the distance from pt1 to pt2 is less than or equal to the sum of radius1
and radius2 then they intersect?

Jim Dee
www.caddee.com

wrote in message
news:5882860@discussion.autodesk.com...
Fatty,

msgbox "YOU ARE THE MAN"

I always had to draw two circles then then draw lines from the intersect
points. I have to do this many times a day. Thank you very^100 much!

God Bless
0 Likes
Message 6 of 9

Anonymous
Not applicable
Oh, my bad
Yes, you are right, CADDee 🙂

Instead of:
If dis > r1 + r2 Then
GetTwoCirclesInters = Null
must be:
If dis < r1 + r2 Then
GetTwoCirclesInters = Null

Thank you

~'J'~
0 Likes
Message 7 of 9

Anonymous
Not applicable
Please, change it as I wrote abow
Glad to help

~'J'~ Message was edited by: Fatty
0 Likes
Message 8 of 9

jbooth
Advocate
Advocate
Depends on your definition of "easy".

http://local.wasp.uwa.edu.au/~pbourke/geometry/2circle/
0 Likes
Message 9 of 9

Anonymous
Not applicable
Agreed, it's easier a bit:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
Option Explicit

Function Get_Dist(p1 As Variant, p2 As Variant) As Double
Get_Dist = Sqr((p1(0) - p2(0)) ^ 2 + ((p1(1) - p2(1)) ^ 2))
End Function
Sub testcircles()
' uses algorithm from here:
' http://local.wasp.uwa.edu.au/~pbourke/geometry/2circle/
Dim oSset As AcadSelectionSet
Dim oEnt As AcadEntity
Dim oCircle As AcadCircle
Dim fcode(0) As Integer
Dim fData(0) As Variant
Dim dxfCode, dxfValue

Dim rad1 As Double
Dim rad2 As Double
Dim segm As Double
Dim hgt As Double
Dim dis As Double

Dim p1 As Variant
Dim p2 As Variant
Dim p3 As Variant
Dim p4(2) As Double
Dim p5(2) As Double

Dim x4 As Double
Dim y4 As Double
Dim x5 As Double
Dim y5 As Double
Dim z As Double

fcode(0) = 0
fData(0) = "CIRCLE"

dxfCode = fcode
dxfValue = fData
With ThisDrawing.SelectionSets
While .Count > 0
.Item(0).Delete
Wend
End With
With ThisDrawing.SelectionSets
Set oSset = .Add("$mycircles$")
End With
ThisDrawing.Utility.Prompt (vbCrLf & "Select two circles")
oSset.SelectOnScreen dxfCode, dxfValue
If oSset.Count <> 2 Then
MsgBox "Wrong number of circles selected" & vbCr & _
"Try again"
End If

Set oEnt = oSset.Item(0)
Set oCircle = oEnt
rad1 = oCircle.Radius
p1 = oCircle.Center

Set oEnt = oSset.Item(1)
Set oCircle = oEnt
rad2 = oCircle.Radius
p2 = oCircle.Center
dis = Get_Dist(p1, p2)

segm = ((rad1 ^ 2 - rad2 ^ 2) + dis ^ 2) / (dis * 2)
hgt = Sqr(Abs(rad1 ^ 2 - segm ^ 2))
With ThisDrawing.Utility
p3 = ThisDrawing.Utility.PolarPoint(p1, .AngleFromXAxis(p1, p2), segm)
End With
x4 = p3(0) + (hgt * (p1(1) - p2(1))) / dis
y4 = p3(1) - (hgt * (p1(0) - p2(0))) / dis
x5 = p3(0) - (hgt * (p1(1) - p2(1))) / dis
y5 = p3(1) + (hgt * (p1(0) - p2(0))) / dis
p4(0) = x4: p4(1) = y4: p4(2) = 0#
p5(0) = x5: p5(1) = y5: p5(2) = 0#

ThisDrawing.ModelSpace.AddLine p4, p5

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'

~'J'~
0 Likes