+ Reply to Thread
Results 1 to 6 of 6

Run series of math formulas with VBA for list of XY pairs

  1. #1
    Registered User
    Join Date
    08-12-2014
    Location
    CA
    MS-Off Ver
    2011
    Posts
    73

    Run series of math formulas with VBA for list of XY pairs

    Hello,

    I have a list of coordinates (X,Y) starting in B2, C2. The length of the coordinates varies, input by the user. This example is 130 pairs. E135 shows what the coordinates look like if plotted. The goal is to find the two closest (X,Y) pairs by using the distance formula to compare (X1,Y1) against (X2,Y2)...(X130,Y130)...(Xn,Yn).

    When the closest pairs are found the distance and coordinates will be known. In our application a hole will be drilled at these points with a diameter. We must drill the hole at each point but two holes can not over lap or come too close to each other. Picture are included in the file. I have done all of the difficult math and its written out step by step, hopefully without error. I need help transforming the formulas into VBA code. The end goal is to identify the closest two points, use a cell as input for the drill bit radius, confirm that the two holes will not come in contact or close proximity where the separation distance is also an input. Finally to return the area between the hole and the safe distance. I have drawn out all the steps and calculations inside the excel file, just looking for someone to put this into VBA code. I think it might be a little difficult.
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Run series of math formulas with VBA for list of XY pairs

    If I am reading the requirement correctly, you want the minimum distance between two coordinates subject to their being 0.038 units apart. The 0.038 comes from each radius is 0.016 plus a gap of 0.006 between them. This code accomplishes it by brute force.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    08-12-2014
    Location
    CA
    MS-Off Ver
    2011
    Posts
    73

    Re: Run series of math formulas with VBA for list of XY pairs

    Hi dflak,
    This is partially correct. I do want to find minimum distance between two coordinates. I.e. the two closest points. But from that I need to calculate the area of an annulus when I use a drill to put a holes at the two closest points. Let's say for example I have point located at (0,0) and one at (1,0). Now the distance between them is 1. Now I use a drillbit and make a hole at (0,0) and (0,1). The radius of the drillbit is 0.25 so I lose 0.25 from the (0,0) and (1,0) so the distance becomes (0+0.25,0) and (1-0.25,0) giving only 0.5 between the two points. Now If I use a drillbit on the hole that has a radius of 0.5, the two holes would touch each other. This would be bad because I need a clearance that changes between the holes. Let say that I need a clearance of 0.3 between the two holes once they are drilled. So I find the two closest points at (0,0) and (1,0), then I drill holes at each point with a radius of 0.25. So same as before the distance between the two holes becomes 0.5, now my clearance is 0.3. So If I find the center point of the 0.5 distance, this gives 0.3/2 clearance. So I am interested in the area between a hole that is 0.25 radius plus the clearance of .15 so I use the formula Area=Pi((radius of outer circle)^2-(radius of inner circle)^2). This is the value I am interested in, the difficulty is, identifying the closest points, then calculating the annulus when both the radius of the hole drilled changes and the clearance requirement between the two holes changes.

    I attached a more clear example
    Attached Files Attached Files
    Last edited by sdl2; 03-30-2017 at 04:09 PM. Reason: Made hand calculated example

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Run series of math formulas with VBA for list of XY pairs

    Where on the sheet, do you define the size of the drill bit? I think that all I have to do is change my fixed 0.038 to a calculated value.

  5. #5
    Registered User
    Join Date
    08-12-2014
    Location
    CA
    MS-Off Ver
    2011
    Posts
    73

    Re: Run series of math formulas with VBA for list of XY pairs

    I don't have a specific place, any cell is fine after column D

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Run series of math formulas with VBA for list of XY pairs

    Here you go. I made a separate sheet to calculate the value.

    You tell it the distance you need between holes and the size of the drill bit and it figures out the distance between centers.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Math in Series
    By jhabijay_10 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-20-2014, 05:26 AM
  2. how to write math formulas?
    By viljar in forum Excel General
    Replies: 1
    Last Post: 11-19-2011, 12:28 PM
  3. Convert simple cell math formulas to VB
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-07-2010, 08:40 AM
  4. Math Formulas and Increments
    By azexlusr in forum Excel General
    Replies: 2
    Last Post: 04-07-2010, 03:52 PM
  5. Math Formulas in a Text Box
    By buddhajb in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-01-2008, 09:53 PM
  6. Replies: 3
    Last Post: 02-16-2006, 07:00 AM
  7. Excel Math formulas
    By [email protected] in forum Excel General
    Replies: 2
    Last Post: 11-15-2005, 11:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1