Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question

migrated from mathematica.stackexchange.com Jun 7 at 17:45

This question came from our site for users of Mathematica.

2  
I'm afraid that this has nothing to do with Mathematica. –  Öskå Jun 7 at 15:33
    
It does.... Basically what I am trying to figure out is: –  AlonQ Jun 7 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 at 15:56
    
Is there a place dedicated for Math in General?? Sorry for posting in the wrong forums –  AlonQ Jun 7 at 16:00

1 Answer 1

Formula for area of shapes can be easily found in many place: http://www.mathsisfun.com/area.html

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

Assume that the square and rectangle have side parallel to axes (otherwise those parameters can't specify them uniquely), then you simply need to check displacement from the corner to the point chosen. Similarly for circle, you simply need to find displacement from the center and then check against the circle equation.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.