Microsoft Interview Question
SDE1sCountry: United States
if the points are all the same or lie in a straight line, then it is not possible
To check if the three points can form a triangle, check the slopes of any two of the edges
like ((y2-y1)/(x2-x1))
ie if the slopes are equal then the points are on a line and cannot be part of a triangle.
To find outer 'normal' circle area:
1. find the centroid of the triangle (ie ((N1+N2+N3)/3, (M1+M2+M3)/3)
2. find the distance between the centroid of the triangle and any of its vertices (ie sqrt((x2-x2)^2 + (y2-y1)^2). This is the radius of the outer 'normal' circle
3. Calculate the area of the normal circle and store it in a variable, say double normalArea
To find inner 'strange circle' area:
1. find midpoint of any one of the triangle edges (ie (x1+x2)/2, (y1+y2)/2)
2. Measure the distance between this midpoint and the centroid of the triangle. This is the radius of
the inner 'strange' circle
3. Calculate its area (pi*r^2)
To find ring area: subtract the inner area from the outer area and return.
if the points are all the same or lie in a straight line, then it is not possible
- confused_coder August 01, 2016To check if the three points can form a triangle, check the slopes of any two of the edges
like ((y2-y1)/(x2-x1))
ie if the slopes are equal then the points are on a line and cannot be part of a triangle.
To find outer 'normal' circle area:
1. find the centroid of the triangle (ie ((N1+N2+N3)/3, (M1+M2+M3)/3)
2. find the distance between the centroid of the triangle and any of its vertices (ie sqrt((x2-x2)^2 + (y2-y1)^2). This is the radius of the outer 'normal' circle
3. Calculate the area of the normal circle and store it in a variable, say double normalArea
To find inner 'strange circle' area:
1. find midpoint of any one of the triangle edges (ie (x1+x2)/2, (y1+y2)/2)
2. Measure the distance between this midpoint and the centroid of the triangle. This is the radius of
the inner 'strange' circle
3. Calculate its area (pi*r^2)
To find ring area: subtract the inner area from the outer area and return.