Ah the Get Nearest Point is done, and also, I develop another new technique to retrieve the contour. Unfortunately, it ran very slow. I need to do optiimzations everywhereh. I uploaded the source, code. If the final code took more than a second, I will not doing the recognitions of the moving object at realtime.

Also I get an idea of geting the euler angle of an object. It is X=DX/hyp Y=DY/hyp Z=(hyp-(DX+DY))/hyp. First, the software need to calibrate the object to obtain the real length of its boundary in real shape. After I get the actual length value, each time the object moving, I can get the euler angle information based only its 2D positions from the above formula. Theoriticaly, based on the knowledge of my 3D programming, it was right for retrieving the inverse matrix of position to euler angle.