MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Jan 20th, 2004, 11:24 PM   #1
ykpotdar
 
Join Date: Aug 2002
Posts: 12
Default Solve 2nd simultaneous eqns

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
ykpotdar is offline   Reply With Quote
Old Jan 21st, 2004, 05:33 AM   #2
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default Re: Solve 2nd simultaneous eqns

Deleted, duplicate response.
__________________
Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Jan 21st, 2004, 05:36 AM   #3
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default Re: Solve 2nd simultaneous eqns

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
__________________
Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Jan 21st, 2004, 05:54 AM   #4
Egress1
 
Egress1's Avatar
 
Join Date: Mar 2003
Location: Lubbock, Texas
Posts: 420
Default Re: Solve 2nd simultaneous eqns

Sure Jay, take the easy ones why don't ya!
__________________
Ken
Egress1 is offline   Reply With Quote
Old Jan 21st, 2004, 06:04 AM   #5
SIXTH SENSE
 
SIXTH SENSE's Avatar
 
Join Date: Oct 2003
Posts: 1,818
Default Re: Solve 2nd simultaneous eqns

Quote:
Originally Posted by ykpotdar
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)
__________________
There is always a better way!!
SIXTH SENSE is offline   Reply With Quote
Old Jan 21st, 2004, 02:06 PM   #6
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default Re: Solve 2nd simultaneous eqns

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.
__________________
Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Jan 21st, 2004, 03:13 PM   #7
Seti
 
Join Date: May 2002
Location: CT
Posts: 2,877
Default Re: Solve 2nd simultaneous eqns

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.
Seti is offline   Reply With Quote
Old Jan 21st, 2004, 06:03 PM   #8
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default Re: Solve 2nd simultaneous eqns

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.
__________________
Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Jan 21st, 2004, 06:13 PM   #9
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default Re: Solve 2nd simultaneous eqns

Quote:
Originally Posted by Egress1
Sure Jay, take the easy ones why don't ya!
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.

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.
__________________
Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Jan 21st, 2004, 07:25 PM   #10
Egress1
 
Egress1's Avatar
 
Join Date: Mar 2003
Location: Lubbock, Texas
Posts: 420
Default Re: Solve 2nd simultaneous eqns

Hi Jay,

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

__________________
Ken
Egress1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 03:59 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2010 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes