Hey, Scripting Guy! Weekend Scripter: How Much Wood?
Microsoft Scripting Guy Ed Wilson here. I am out in my woodworking shop today, and I am laying out an arch that I will use to create a curved top for a box. I need to know how much wood will be required to make that arch—the radius of the arch. Another use might be to measure for drywall when creating an arch over a door. How do I do this? I could use a pencil and a string to draw the arch, and then try to use a tape measure to bend along the arch and arrive at the distance that way; however, a simple formula would be easier to use. The formula is seen here:
(X/2)2 + Y2 / 2Y = R
The formula can be visualized by looking at the following image.
A Windows PowerShell function to perform this calculation would save some time. To create the function in Windows PowerShell, I will need to use the static POW method from the system.math .NET Framework class. Here is the function:
([math]::POW($x/2,2) + [math]::POW($y,2)) / (2*$y)
To use the function, you need to either edit the script containing the function as seen in the following image, or you will need to add it to your profile, a module, or dot source it into your current session. You do not need to supply parameter names because you can use positional arguments.
The key to unlocking the ability of Windows PowerShell to create useful formulas is to leverage the static methods from the system.math class. You can easily see them by using the Get-Member cmdlet, as shown here:
PS C:> [math] | Get-Member -Static | Format-Table name, membertype -AutoSize
Most of the time, the methods and properties are self-explanatory. When they are not, use MSDN to fill in the gaps.
Well, that is all there is to messing around with arches. If you want to know exactly what we will be looking at tomorrow, follow us on Twitter or Facebook. If you have any questions, send e-mail to us at email@example.com or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson and Craig Liebendorfer, Scripting Guys