Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Find angle and rotation of point

hi , i want to find the angle. i find the following code can anyone explain me its meaning. here why p0,p1,p2 are being findout. what is the meaning of (uxvx + uyvy) / sqrt((uxux + uyuy)(vxvx + vyvy) and (uxvy - vx*uy) here.

double angle(std::vector<cv::Point>& contour, int pt, int r)
{
    int size = contour.size();
    cv::Point p0 = (pt>0) ? contour[pt%size] : contour[size - 1 + pt];
    cv::Point p1 = contour[(pt + r) % size];
    cv::Point p2 = (pt>r) ? contour[pt - r] : contour[size - 1 - r];

    double ux = p0.x - p1.x;
    double uy = p0.y - p1.y;
    double vx = p0.x - p2.x;
    double vy = p0.y - p2.y;
    return (ux*vx + uy*vy) / sqrt((ux*ux + uy*uy)*(vx*vx + vy*vy));
}

int rotation(std::vector<cv::Point>& contour, int pt, int r)
{
    int size = contour.size();
    cv::Point p0 = (pt>0) ? contour[pt%size] : contour[size - 1 + pt];
    cv::Point p1 = contour[(pt + r) % size];
    cv::Point p2 = (pt>r) ? contour[pt - r] : contour[size - 1 - r];

    double ux = p0.x - p1.x;
    double uy = p0.y - p1.y;
    double vx = p0.x - p2.x;
    double vy = p0.y - p2.y;
    return (ux*vy - vx*uy);
}

thanks!!