# Few Math Questions

So I'm working on a small kinda homework I got... Currently I'm building a small console application using .NET and C#... It is supposed to behave this way:

When the user enters the name of a shape followed by the corresponding number of numeric parameters, define that shape and keep it in memory. The numbers may be of type double. Examples:

circle 1.7 -5.05 6.9 square 3.55 4.1 2.77 rectangle 3.5 2.0 5.6 7.2 triangle 4.5 1 -2.5 -33 23 0.3 donut 4.5 7.8 1.5 1.8

For the circle, the numbers are the x and y coordinates of the centre followed by the radius. For the square it is x and y of one corner followed by the length of the side. For the rectangle it is x and y of one corner followed by the two sides. For the triangle it is the x and y coordinates of the three vertices (six numbers in total). For the donut it is the x and y of the centre followed by the two radiuses.

In addition, every time such a line is entered, the application should give it a unique identifier and print it out in a standardised form, for example:

=> shape 1: circle with centre at (1.7, -5.05) and radius 6.9

That is not really complicated and I know kinda how to do all that... The problem is with some of the calculations the app is supposed to do, which are Math Operations and I don't really remember a lot about how to apply them... For Example:

When the user enters a pair of numbers, the application should print out all the shapes that include that point in the (x, y) space, i.e. it should print out shape X if the given point is inside X. (A point is inside a donut shape if it is inside the outer circle but not inside the inner one.)

It should also print out the surface area of each shape found, and the total area of all the shapes returned for a given point.

So I guess what I'm really asking is help on how to calculate the surface of those shapes with the given parameters, how to calculate the areas (this ones a bit easier to researcher but might as well ask) and lastly how, given a pair of numbers, should I calculate whether or not a certain Shape contains that point in its X and Y space...

Thanks for any help you can give me and have a nice day.

-

## migrated from mathematica.stackexchange.comJun 7 '14 at 17:45

This question came from our site for users of Mathematica.

I'm afraid that this has nothing to do with Mathematica. – Öskå Jun 7 '14 at 15:33
It does.... Basically what I am trying to figure out is: – AlonQ Jun 7 '14 at 15:50
What you're asking is a perfectly reasonable set of questions, but not for this StackExchange. The topic here is the software Mathematica and not mathematics generally. – Christopher Cole Jun 7 '14 at 15:56
Is there a place dedicated for Math in General?? Sorry for posting in the wrong forums – AlonQ Jun 7 '14 at 16:00

Ray casting algorithm is commonly used to find whether point is inside or outside a polygon: http://en.wikipedia.org/wiki/Point_in_polygon. Since your polygon here have 3 sides only, it's even easier. An alternative approach when all you have to deal with is triangle is to simply check that the point is inside 2 of the angle formed using cross-product: to check that $D$ is inside $ABC$ simply make sure that $((\vec{D}-\vec{A})\times(\vec{B}-\vec{A}))((\vec{D}-\vec{A})\times(\vec{C}-\vec{A}))$ and $((\vec{D}-\vec{B})\times(\vec{A}-\vec{B}))((\vec{D}-\vec{B})\times(\vec{C}-\vec{B}))$. Another approach is this formula http://mathworld.wolfram.com/TriangleInterior.html