Showing posts with label SIMILAR objects. Show all posts
Showing posts with label SIMILAR objects. Show all posts

Friday, March 1, 2013

LOGIC to prove SIMILAR Objects are EQUAL



While developing GEM (GEstures with Mouse) the biggest problem i faced is, "the user drawn gesture is most of the times smaller / bigger than already defined gesture" but they are almost same in shape. So, i used a logic to prove SIMILAR Objects (Different in size but with same shapes ) are EQUAL.

LOGIC:
Let us consider two similar circles A, B as shown in picture.
The co-ordinates of Circle A are
(x1, y1) = (6, 4)
(x2, y2) = (8, 6)
(x3, y3) = (6, 8)
(x4, y4) = (4, 6)

The co-ordinates of Circle B are
(X1, Y1) = (6, 3)
(X2, Y2) = (9, 6)
(X3, Y3) = (6, 9)
(X4, Y4) = (3, 6)

now we re-calculate the  above co-ordinates using following formulas

X =  [X - [Xmax+Xmin]/2] / [Xmax-Xmin]+ 0.5 ---------(1)

        where Xmin = min(x1,x2,x3,x4) for circle A
                   Xmax = max(x1,x2,x3,x4) for circle A
                   X = x1, x2, x3, x4 for circle A

                   Xmin = min(X1,X2,X3,X4) for circle B               
                   Xmax = max(X1,X2,X3,X4) for circle B
                   X = X1, X2, X3, X4 for circle B

Y =  [Y - [Ymax+Ymin]/2] / [Ymax-Ymin]+ 0.5 ------------(2)

        where Ymin = min(y1,y2,y3,y4) for circle A
                    Ymax = max(y1,y2,y3,y4) for circle A
                    Y = y1, y2, y3, y4 for circle A
                   
                   Ymin = min(Y1,Y2,Y3,Y4) for circle B
                   Ymax = max(Y1,Y2,Y3,Y4) for circle B
                   Y = Y1, Y2, Y3, Y4 for circle B
                  
Re-Calculating Circle A points:

Xmin = min(6, 8, 4, 6) = 4
Xmax = max(6, 8, 4, 6) = 8


Ymin = min(4, 6, 6, 8) = 4
Ymax = max(4, 6, 6, 8) = 8

new x1 =  (6 - (8+4) / 2)/4 + 0.5 = 0.5
new y1 =  (4 - (8+4) / 2)/4 + 0.5 = 0.0

in the same manner

new x2 = 1.0
new y2 = 0.5

new x3 = 0.5
new y3 = 1.0

new x4 = 0.0
new y4 = 0.5

Re-Calculating Circle B points:

Xmin = min(6, 9, 6, 3) =3
Xmax = max(6, 9, 6, 3) =9

Ymin = min(3, 6, 9, 6) =3
Ymax = max(3, 6, 9, 6) =9

new X1 = (6 - (9+3)/2)/(9-3) + 0.5 = 0.5
new Y1 = (3 - (9+3)/2)/(9-3) + 0.5 = 0.0

in the same manner

new X2 = 1.0
new Y2 = 0.5

new X3 = 0.5
new Y3 = 1.0

new X4 = 0.0
new Y4 = 0.5

After Re-calculating Circle A & B points using Formula (1) and (2)

x1 = X1; x2 = X2; x3 = X3; x4 = X4; and 
y1 = Y1; y2 = Y2; y3 = Y3; y4 = Y4;


Hence, SIMILAR Circles A and B are EQUAL

Note: Not only circles using this formulas any two similar drawing shapes can be proved to equal.