Adobe Interview Question
Software Engineer / DevelopersYou are assuming that the centre, the square top-left of the square and the small rectangle bottom right fall in the straight line. How can you be sure of that?
@CuriousMe : The only thing I am assuming here is that the center of the circle is the origin. The answer doesn't change if the center is anywhere else also.
hi paras,
which points cordinte is r-7, r-14 can u plz explian clearly ..i think its shoud be either r-7,14 or 7,r-14
plz correct me m missing sumthing..here..plz specfiy the points fro cordinate u have calculated
@Algoseekar : (r-7, r-14) is the vertex of the rectangle that is falling on the circle.
As I said the top-right vertex of the square will be (r,r) and assuming the rectangle is along the top-right vertex.
So the top-right vertex of the rectangle will be (r,r). since the length and width of rectangle is 7, 14 so the diagonally opposite vertex of the rectangle (the one that is falling on the circle) will be (r-7, r-14) or (r-14, r-7).
This can be explained in a bttr way thru diagram (but I can't draw it here)
@paras: id circle is enclosed in the square and touching all four sides of the square then don't you think that circle's center and square's center are one and the same. and in this case id you place this center at origin, i think top right vertex of the square will be (r*sqrt(2),r*sqrt(2)) not (r,r)....
correct me if i m wrong.....
But the answer is correct and it is true that the point where rectangle touches the circle will be (r-7,r-14) and with the trigonometry its simply gives the answer by (r-7)^2+(r-14)^2=r^2 which is 35.
My doubt was which vertex you are talking about, the vertex where circle touches the square or the top right square vertex?
Maybe some misunderstanding in the nomenclature.... but approach is excellent.....
Let the center of the circle be O and the point on the circumference of the circle where the rectangle touches the circle be A. Now draw a line from O to the top most point of the circle, and draw a line perpendicular to this line from A. Lets call the point where these two lines meet B. Now OA = r, AB = r-14 and OB = r-7. Since, the triangle OBA is a right angled triangle:
r*r = (r-7)*(r-7) + (r-14)*(r-14)
Solve this equation and you have the radius of the circle!
r = 21 + sqrt(406)
assuming that r is the radius of the circle
Diagonal of the main square = r* sqrt(2);
Diagonal of the rectangle= sqrt(14*14 + 7*7);
hence we just need to solve the following
r*sqrt(2) - r = sqrt(14*14 + 7*7)
@anon : The diagonals of bigger square and smaller rectangle will not be the same line always , So I believe you can't just subtract them to get the radius of the circle. Correct me if I am wrong.
Aren't the circle is enclosed in a square? Hence, the top-left corner of the square is {r*sqr(2),r*sqr(2)} not (r,r)
You are talking about the case in which the square is inside the circle, but the question here is circle inside the square.
here all sides of the square will be tangents to the circle.
The equation of these tangents will be (assuming center as origin) :
1. x = r
2. x = -r
3. y = r
4. y = -r
when you solve this u get (r,r), (r,-r), (-r,r), (-r,-r)
Lets assume the radius of circle is 'r' and centre of circle is the origin.
- Paras March 19, 2011So the coordinate of top right vertex of the enclosing square will be (r,r).
now the co-ordinate of the rectangle falling on the circle will be
(r-7, r-14) or (r-14, r-7).
Since this point is falling on the circle it has to follow the circle equation i.e
x^2 + y^2 = r^2
putting the values of x and y
(r-7)^2 + (r-14)^2 = r^2
=> r^2 - 42r + 245 = 0
=> (r-7)*(r-35) = 0
so r = 7 or r = 35
now r ca not be 7
so r = 35