Solve 2nd simultaneous eqns

ykpotdar

New Member
Joined
Aug 1, 2002
Messages
12
Hi,

I know coordinates of two points (x & y ) and want to find the center of the circle of radisu R (known) passing through these points. How can I get EXCEL to do it? We can assume that R, x and y are three cells in a EXCEL spreadsheet. I want to do this for about 100 points.

Thanks,

-Yogesh
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,

This is untested, so try this out on your data and report your results. It will find 1 of the 2 solutions (it should correctly identifythe situations where 0, 1, or infinite solutions are possible).

The return_type should be an "x" or a "y" string.

Code:
Function FindCircleCenter(Return_Type As String, Radius As Double, _
                          x_0 As Double, y_0 As Double, _
                          x_1 As Double, y_1 As Double)


Dim MidptDist As Double
Dim x_coordinate As Double
Dim y_coordinate As Double
Dim x_mid As Double
Dim y_mid As Double
Dim Slope_Test As Double
Dim Orthogonal_Slope As Double
Dim Triangle_Height As Double
Dim Theta As Double

MidptDist = Distance_Between_Points(x_0, y_0, x_1, y_1) / 2
x_mid = Midpoint_Between_Points("X", x_0, y_0, x_1, y_1)
y_mid = Midpoint_Between_Points("Y", x_0, y_0, x_1, y_1)
Triangle_Height = Sqr(Radius ^ 2 - MidptDist ^ 2)

If MidptDist > Radius Then
    FindCircleCenter = "no solution"
    Exit Function
ElseIf MidptDist = Radius Then
    x_coordinate = x_mid
    y_coordinate = y_mid
    GoTo ExitTheFunction
ElseIf MidptDist = 0 Then
    FindCircleCenter = "infinite solutions"
    Exit Function
End If


If x_0 = x_1 Then
    x_coordinate = x_0 + Triangle_Height
    y_coordinate = y_mid
    GoTo ExitTheFunction
End If
Slope_Test = Slope_Between_Points(x_0, y_0, x_1, y_1)
If Slope_Test = 0 Then
    x_coordinate = x_mid
    y_coordinate = y_mid + Triangle_Height
    GoTo ExitTheFunction
Else
    Orthogonal_Slope = -1 / Slope_Test
    Theta = Atn(Orthogonal_Slope)
    x_coordinate = x_mid + Triangle_Height * Cos(Theta)
    y_coordinate = y_mid + Triangle_Height * Sin(Theta)

End If

ExitTheFunction:

Select Case UCase(Left(Return_Type, 1))
    Case Is = "X": FindCircleCenter = x_coordinate
    Case Is = "Y": FindCircleCenter = x_coordinate
    Case Else: FindCircleCenter = CVErr(xlErrValue)
End Select

End Function

Function Distance_Between_Points(x_0 As Double, y_0 As Double, _
                                 x_1 As Double, y_1 As Double, _
                                 Optional z_0 As Double = 0, _
                                 Optional z_1 As Double = 0)
Dim x As Double
Dim y As Double
Dim z As Double

x = (x_1 - x_0) ^ 2
y = (y_1 - y_0) ^ 2
z = (z_1 - z_0) ^ 2
                        
                        
Distance_Between_Points = Sqr(x + y + z)
End Function

Function Slope_Between_Points(x_0 As Double, y_0 As Double, _
                              x_1 As Double, y_1 As Double)
    
Slope_Between_Points = (y_1 - y_0) / (x_1 - x_0)
End Function

Function Midpoint_Between_Points(Return_Type As String, _
                                 x_0 As Double, y_0 As Double, _
                                 x_1 As Double, y_1 As Double, _
                                 Optional z_0 As Double = 0, _
                                 Optional z_1 As Double = 0)
                        
Dim x As Double
Dim y As Double
Dim z As Double
                        
x = (x_1 - x_0) / 2
y = (y_1 - y_0) / 2
z = (z_1 - z_0) / 2

Select Case UCase(Left(Return_Type, 1))
    Case Is = "X": Midpoint_Between_Points = x_0 + x
    Case Is = "Y": Midpoint_Between_Points = y_0 + y
    Case Is = "Z": Midpoint_Between_Points = z_0 + z
    Case Else: Midpoint_Between_Points = CVErr(xlErrValue)
End Select

End Function
 
Upvote 0
ykpotdar said:
Hi,

I know coordinates of two points (x & y ) and want to find the center of the circle of radisu R (known) passing through these points. How can I get EXCEL to do it? We can assume that R, x and y are three cells in a EXCEL spreadsheet. I want to do this for about 100 points.

Thanks,

-Yogesh
hi!
do you mean that X is a point with corrdiante(x1,y1) and Y is another point with coordiante (x2,y2)
 
Upvote 0
Hi,

In the code, I have the following...

Code:
Select Case UCase(Left(Return_Type, 1)) 
    Case Is = "X": FindCircleCenter = x_coordinate 
    Case Is = "Y": FindCircleCenter = x_coordinate 
    Case Else: FindCircleCenter = CVErr(xlErrValue) 
End Select

The "Y" case should read

Case Is = "Y": FindCircleCenter = y_coordinate

Sorry about that. :oops:
 
Upvote 0
In most cases, aren't there 2 solutions? Once one is found, there should be another located triangle hieght away from the line segment joinging x and y in the opposite direction of the first solution. I didn't follow all of Jay's code, so if there are two solutions falling out of this, I apologize.
 
Upvote 0
Hi Seti,

In my preamble, I note that there are two solutions in most cases, but my (untested) function only returns one of them (a solution in quadrants I or IV).

If I get some time today, I will give it some testing and report back. I hope the OP gives it a more thorough test with the actual data used.
 
Upvote 0
Egress1 said:
Sure Jay, take the easy ones why don't ya! :pray:

Hi Ken,

It may be easy for you, but I got confused writing this at first and so decided to separate each piece into its own custom function. :lol: :lol: :lol:

Actually, I think that is the way to go in many instances, so I am going to keep to that strategy from now on. It may not be the absolutely most efficient way in terms of computer performance, but it is the most flexible and adaptable.
 
Upvote 0
Hi Jay,

I was being sarcastic my friend. I am most impressed by your knowledge (not sarcastic).

:beerchug:
 
Upvote 0

Forum statistics

Threads
1,223,922
Messages
6,175,384
Members
452,639
Latest member
RMH2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top