objective c - Find mid-point between two rectangles, intersection + edge aware -


as seen in image, find mid-point between 2 rectangles. if rectangles intersecting mid-point between centers of rectangles. if rectangles not intersecting, mid-point from/between edges of rectangles.

i write in obj-c or swift.

thx

enter image description here

in situation should check first check wether there rectangles overlapped or not.

to check wether overlapped or not

cgrect recta = cgrectmake(50, 50, 50, 50);

cgrect rectb = cgrectmake(100, 100, 50, 50);

if (cgrectgetminx(recta) < cgrectgetmaxx(rectb)  &&  cgrectgetmaxx(recta) > cgrectgetminx(rectb)  &&     cgrectgetminy(recta) < cgrectgetmaxy(rectb)  &&  cgrectgetmaxy(recta) > cgrectgetminy(rectb) ) {     nslog(@"overlapped");  } else {     nslog(@"not overlapped"); } 

after finding overlapped or not find centres of both rectangles , whatever want.

to find center.

cgpoint  centerb = cgpointmake((cgrectgetminx(rectb) + cgrectgetmaxx(rectb))/2, (cgrectgetminy(rectb) + cgrectgetmaxy(rectb))/2); 

cgpoint centera = cgpointmake((cgrectgetminx(recta) + cgrectgetmaxx(recta))/2, (cgrectgetminy(recta) + cgrectgetmaxy(recta))/2);


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -