当前位置:网站首页>Common scenes of vector product in image

Common scenes of vector product in image

2022-04-23 21:57:00 Three stone orders

Cross product ( Vector product ) Definition :

1、a×b or a∧b, The result is scalar ;
2、 Vector product |c|=|a×b|=|a||b|sin<a,b>, namely c The length of is numerically equal to a,b, The included angle is θ The area of the parallelogram formed ;
3、a=(x1,y1),b=(x2,y2), be a×b=x1y2-y1x2;
4、a×b Less than 0, vector a Less than 180° Rotate counterclockwise to vector b;a×b Greater than 0, vector a Less than 180° Rotate clockwise to vector b;a×b be equal to 0, vector a Parallel and vector b;

Reference scene 1:

OpenCV in contourArea Contour area algorithm , Suppose that the contour point (A、B、C) Sort clockwise ,O Origin ,OA×OB Is the area of the corresponding parallelogram , Half is a triangle OAB The area of ( Green area )
Then there are ABC The area of =OA×OB×0.5+OB×OC×0.5+OC×OA×0.5, among OC×OA In the opposite direction ;
 Insert picture description here

Reference scene 2:

When a set of points with any distribution is sorted clockwise by bubbling method , You need to determine the direction of the two vectors , Such as OA Rotate to OB Clockwise or counterclockwise .

bool IsAnticlockwise(Point O, Point a, Point b)
{
    
	// If oa Rotate clockwise to ob The angle of is less than 180°, return false, Otherwise return to true
	if (a.x >= 0 && b.x < 0)
		return true;
	if (a.x == 0 && b.x == 0)
		return a.y > b.y;
	// vector OA Sum vector OB Cross product of 
	int det = (a.x - O.x) * (b.y - O.y) - (b.x - O.x) * (a.y - O.y);
	if (det < 0)
		return true;
	if (det > 0)
		return false;
	// vector OA Sum vector OB Collinear , Judge the size by distance 
	int d1 = (a.x - O.x) * (a.x - O.x) + (a.y - O.y) * (a.y - O.y);
	int d2 = (b.x - O.x) * (b.x - O.y) + (b.y - O.y) * (b.y - O.y);
	return d1 > d2;
}

Reference scene 3:

Judge whether the line segments intersect by the positive and negative cross product of two vectors ;
https://blog.csdn.net/li1615882553/article/details/80372202
 Insert picture description here

other :

Pay attention to distinguish dot product ( To multiply ), The result is a vector ,v1.v2=|v1|*|v2|*cosθ

版权声明
本文为[Three stone orders]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204200615437236.html