# C# code/function to calculate "area of irregular rectangular" and "volume of irregular cube"

• ### Question

• I want to calculate "area of irregular rectangular" and "volume of irregular cube" using C# based on the coordinate (X, Y, Z) of each corner point. Is there function to perform this calculation in C#?

fialbz

Saturday, July 5, 2014 11:02 AM

• Hi Fialbz,

There is no existing project about how to Polyhedral Volume Calculations using C#. I think you should find the way how math do it and then implement it using C#. I pick up an article about this problem, but the article was about javascript implementation. I hope you can get inspiration from it. See more information from http://www.codeproject.com/Articles/13666/Polyhedra-Volume-Calculations-A-JavaScript-Impleme.

Regards,

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. &lt;br/&gt; Click &lt;a href=&quot;http://support.microsoft.com/common/survey.aspx?showpage=1&amp;scid=sw%3Ben%3B3559&amp;theme=tech&quot;&gt; HERE&lt;/a&gt; to participate the survey.

Monday, July 14, 2014 7:07 AM

### All replies

• X,Y,Z will not uniquely give a area with irregular rectangles/cubes.  See webpage below

jdweng

Saturday, July 5, 2014 12:57 PM
• Joel,

All sides of the "irregular cube" are plain perfectly (no curve at all). Thus, the “volume of irregular cube” can be calculated uniquely based on X, Y, Z coordinates.

2D shape of “irregular rectangular” has straight lines for all lines (no curve at all). Thus, the “area of irregular rectangular” can be calculated uniquely based on X, Y coordinates.

The link that you gave to us could be had curve in the sides or lines. It is not my question. Thanks.

fialbz

Sunday, July 6, 2014 10:59 AM
• "The link that you gave to us could be had curve in the sides or lines."

How so? He gave you a link for "quadrilateral" - a polygon with 4 sides. Polygons do not contain curves.

In general, the .NET framework doesn't not do geometry with the exception of some functionality that can be found in WPF. For example you can compute the area of a 2D polygon by using the PathGeometry class:

```var polygon = new PathFigure {
IsClosed = true,
StartPoint = new Point(10, 10),
Segments = {
new LineSegment(new Point(100, 100), false),
new LineSegment(new Point(50, 200), false)
}
};

var geometry = new PathGeometry {
Figures = { polygon }
};

Console.WriteLine(geometry.GetArea());
```

There's nothing like this for 3D geometry so you'll have to do it yourself.

I have no idea what an "irregular rectangular" is. Everyone knows that a rectangle is a polygon with 4 sides and 4 right angles. But "irregular rectangular" ?! Same thing about "irregular cube".

Sunday, July 6, 2014 12:10 PM
• I wasn't refereeing to curves.  It the sides of the 3D isn't perpendicular to the base of the 3D x,y,z doesn't apply.

jdweng

Sunday, July 6, 2014 12:18 PM
• I mean "irregular rectangular" is 2D polygon with 4 sides. Your code solved my question to calculate the area of "irregular rectangular".

I am still waiting for C# code either from console-application or WPF-application that can calculate the volume of "irregular cube". Thanks.

fialbz

Sunday, July 6, 2014 11:36 PM
• Hi Fialbz,

There is no existing project about how to Polyhedral Volume Calculations using C#. I think you should find the way how math do it and then implement it using C#. I pick up an article about this problem, but the article was about javascript implementation. I hope you can get inspiration from it. See more information from http://www.codeproject.com/Articles/13666/Polyhedra-Volume-Calculations-A-JavaScript-Impleme.

Regards,

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. &lt;br/&gt; Click &lt;a href=&quot;http://support.microsoft.com/common/survey.aspx?showpage=1&amp;scid=sw%3Ben%3B3559&amp;theme=tech&quot;&gt; HERE&lt;/a&gt; to participate the survey.

Monday, July 14, 2014 7:07 AM