# Hey, Scripting Guy! Weekend Scripter: How Much Wood?

### Hey, Scripting Guy! Weekend Scripter: How Much Wood?

• Likes

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 archthe 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:

Function Get-Arch
{
Param(\$x, \$y)
([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

Name            MemberType
----            ----------
Abs                 Method
Acos                Method
Asin                Method
Atan                Method
Atan2               Method
BigMul              Method
Ceiling             Method
Cos                 Method
Cosh                Method
DivRem              Method
Equals              Method
Exp                 Method
Floor               Method
IEEERemainder       Method
Log                 Method
Log10               Method
Max                 Method
Min                 Method
Pow                 Method
ReferenceEquals     Method
Round               Method
Sign                Method
Sin                 Method
Sinh                Method
Sqrt                Method
Tan                 Method
Tanh                Method
Truncate            Method
E                 Property
PI                Property

PS C:\>

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 scripter@microsoft.com or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson and Craig Liebendorfer, Scripting Guys

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
• Ed,

Aren't you going to use too much wood?

I get (X*X)/(8*y)+y/2=R

Using X=96, y=12 gives:

(96*96)/(8*12)+12/2=R->102

versus the formula given:

(96/2)*(96/2)+(12)*(12)/(2*12)=R->2130

• versus the formula given:

(96/2)*(96/2)+(12)*(12)/(2*12)=R->2310