Tuesday, 21 February 2017

FOUR SEASONERS

QUESTION DESCRIPTION :

Dinesh also joined the group of 3 idiots and now their group is called Four Seasoners. Meanwhile, Binoy has moved to a new house in the same locality. Now the houses of Ajay, Binoy and Chandru are in the located in the shape of a triangle. Dinesh also has moved to a house in the same locality. When Ajay asked Dinesh about the location of his house , Dinesh said that his house is equidistant from the houses of the other 3. Though Ajay was good in Mathematics, he was puzzled. Can you please help Ajay out?

Given the 3 vertices {(x1,y1), (x2,y2) and (x3,y3)} of a triangle, write a C program to determine the point which is equidistant from all the 3 vertices.

Input Format:
Input consists of 6 integers. The first integer corresponds to x1 . The second integer corresponds to y1. The third and fourth integers correspond to x2 and y2 respectively.
The fifth and sixth integers correspond to x3 and y3 respectively.


TEST CASE 1

INPUT

2 4
10 15
5 8

OUTPUT

Dinesh house is located at (5.7,9.0)


EXPLANATION :

The code requires you to take input , 3 set of coordinates ( x,y ) , for three friends of Dinesh and calculate the coordinates of his house such that is it at equal distance form all the three houses.
If we consider the 3 houses to be the three vertices of the triangle , then the point at equal distance of  all of them is the circumcentre Circumcenter ). So we have to calculate the circumcenter of the triangle , whose coordinates have been given.


QUESTION ISSUES :

The circumcenter of the triangle in the given example ( sample I/O ) is ( -230.5 , 181.5 ) , but the output given,  corresponds to the centroid of the given triangle. So either the input or output needs to be changed or the question description. For the sake of getting the correct output , I will calculate the centroid instead of the circumcenter. ( The triangle should be an equilateral triangle for circumcenter and centroid to coincide ( no such condition is given ) )


ALGORITHM :

  • Take 6 inputs from the user corresponding to the x,y coordinates of the three houses ( x1,y1,x2,y2,x3,y3 )
  • Calculate the centroid of the triangle ( (x1+x2+x3)/3.0 , (y1+y2+y3)/3.0 )
  • Print the result with the required message.
 
 SOLUTION : (Please use this as reference only)

CODE

No comments:

Post a Comment