# 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 (ux*vx + uy*vy) / sqrt((ux*ux + uy*uy)*(vx*vx + vy*vy) and (ux*vy - 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!!

Angle and rotation of a point? I do not understand can you give an example

to compute an angle you need three point. i suggest you to use the function below. you can find example usage here

can you explain me why the following is done : what is its meaning

operator % and ? Your question is not about OpenCV. You should read a book about C++ and geometry

Dear LBerger, i want to know conceptually why this is being done to find 3 points. with a difference of 16. i know the meaning of operator %.

As you don't answer to my first question

what is angle and rotation point ?and you don't answer too @sturkmen and you can give some lines outside of context. I can imagine many things about your problem. People who try to answer to question want only to help people.Now with your last question a contour is a set of order points from i to size-1 in your example. distance from Point i to (i+1)%size could be only 1 if it's a 4-connex contour( 8-connex 1 or square rooth of 2) and angle relative to x axis 0,90,180 or -90 degree. Now If you want to have an estimation what is your contour orientation around i point it's better to take a point far from i (but not far 16 and -16 are good values).

Hence we've got two vectors and ...(more)

the % makes it wrap around the end, and start at the beginning again