Alignment of Polygons - silverlight-5.0

I have two polygons on a Canvas. My requirement is that if i drag one polygon over other then i want to find the closest point of both polygons and align the second polygon accordingly.
For example below are two polygons, I am dragging maroon polygon on to blue one.
So I want to find the nearest corner points and align the maroon polygon accordingly, something like below:
Thanks,
Abdi

Related

OpenGL: How to fill a polygon gradiently smoothly without spurious star edges

Suppose the polygon is a hexagon.
To fill it gradiently, assume there are many smaller hexagons inside.
The smaller the hexagon, the pixel on that hexagon has a brighter color.
However, after I finish it, I find that there are spurious star edges between the center and the corners, like in the attached image (ignore the two discs inside).
How should I design an algorithm to make the filling more smoothly?

Colour map in Qt

I am new to Qt. I am trying to make a simple map like in the picture bellow, and color each slot a different color based on some value calculated by my program. Then when I tick a checkbox, the value will be displayed on the slot on top of the color. So how can I do this? Any pointing is greatly appreciated.
The trick to drawing such figures is to realize that it's possible to draw a single pixel multiple times.
Each slot is a rectangle, drawn in either white or a color.
On top of those rectangles, you draw the following things:
A grid of black lines
A black circle (not filled)
A number of white circles, around the black circle.
The last step erases colored pixels outside the circle from step 2.

Undistorting concentric circles in opencv

I have an image consisting of concentric circles. I'm trying to undistort the image so that the circles are equal spacing apart around the edges, as if the camera is parallel to the plane. (Some circles will appear closer to the next which is fine, I just want equal spacing all around the edges between the two adjacent circles)
I've tried to estimate a rigid transform by specifying points of the outer circle, but it distorts the inner circles too much, and I've tried a findhomography by specifying points of all the circles, and comparing with points of circles of where they should be.
From what I see the outer circles are 'squished' vertically, so need to be smushed up horizontally, but the inner circles are more circular. What can I do to undistort this image?
https://code.google.com/p/ipwithopencv/source/browse/trunk/ThinPlateSpline/ThinPlateSpline/?r=4
Using this implementation of Thin Plate Spline, I was able to input a set of points representing all the distorted circles, and another set of points which represent where they should be, to get the desired output. It isn't absolutely perfect, but it's more than good enough!

Calculate vertices of a bounding box

I am stumped by this problem which looks very simple. I have a 2D bounding box of which I have two corner points. I wish to determine the remaining two corner points. An important constraint: the bounding box can be oriented in any way and not necessarily aligned to the horizontal and vertical axes (i.e. x and y axes).
I wish to do this as I want to raster scan the bounding box.
I'm sure this is not an answer you want to hear, however, as mentioned here before, two diagonally opposite points are not enough to define a rectangle on a 2D surface. As a picture is worth a thousand words, here's a picture of two different rectangles sharing the same diagonally opposite points.
As mentioned in the comments, you don't have complete information. Let me explain: Draw a dummy rectangle that you want to find the points for -- make sure the rectangle is rotated i.e. not "flat".
Now, pick the top-left and bottom-right points -- treat them as the top-left and bottom-right points of a rectangle that is sitting flat on the x-axis. This shows that you can have at least two rectangles with the same two opposing points. Similarly, you can alter the angle of tilt and get an infinite number of points.
If you want a unique rectangle, you need to define at least the tilt. Hope that helps.

Calculate minimum area rectangle for a polygon

I have a need to calculate the minimum area rectangle (smallest possible rectangle) around the polygon.
The only input i have is the number of points in polygon.
I have the co-ordinates of the points also.
This is called Minimum Bounding Box, it's most basic algorithm used in OCR packages. You can find an implementation using Rotating Calipers from the OpenCV package. Once you get the source code, check out this file,
cv/src/cvrotcalipers.cpp
The method you need is cvMinAreaRect2().
Use the rotating calipers algorithm for a convex polygon, or the convex hull otherwise. You will of course need the coordinates of the points in the polygon, not just the number of points.
First do a grahm-scan and get the convex hull of the set of points. Then you can use something like minimum rectangle discussed here
Follow the following algorithm
Rotate the polygon onto the XY plane
Pick 1 edge and align this edge with the X axis(use arctan). Use the min/max x,y to find the bounding rectangle. Compute Area and store in list
Do the same for remaining edges in clipped polygon.
Pick the rectangle with the minimum Area.
Rotate Bounding Rectangle back for Coplanar reverse rotation of Step 1 and step 2
for more detail check link Minimum-Area-Rectangle
Obviously, you'll need the coordinates of the points to get the answer. If the rectangle is aligned to the X and Y aces, then the solution is trivial. If you want the smallest possible rectangle, at any angle, then you'll need to do some sort of optimization process.