human
Check if given polygon is a convex polygon or not | Utility function to find cross product of two vectors.
Stores coefficient of X direction of vector A [ 1 ] A [ 0 ].
Stores coefficient of Y direction of vector A [ 1 ] A [ 0 ].
Stores coefficient of X direction of vector A [ 2 ] A [ 0 ].
Stores coefficient of Y direction of vector A [ 2 ] A [ 0 ].
Return cross product.
Function to check if the polygon is convex polygon or not.
Stores count of edges in polygon.
Stores direction of cross product of previous traversed edges.
Stores direction of cross product of current traversed edges.
Traverse the array.
Stores three adjacent edges of the polygon.
Update curr.
If curr is not equal to 0.
If direction of cross product of all adjacent edges are not same.
Update curr.
Driver code"
Solution in Python:
 ... Write me a code to check if given polygon is a convex polygon or not and the other steps required?
assistant
#Here is code to check if given polygon is a convex polygon or not and the other steps required.
 def CrossProduct ( A ) :
	X1 = ( A [ 1 ] [ 0 ] - A [ 0 ] [ 0 ] )
	Y1 = ( A [ 1 ] [ 1 ] - A [ 0 ] [ 1 ] )
	X2 = ( A [ 2 ] [ 0 ] - A [ 0 ] [ 0 ] )
	Y2 = ( A [ 2 ] [ 1 ] - A [ 0 ] [ 1 ] )
	return ( X1 * Y2 - Y1 * X2 )
def isConvex ( points ) :
	N = len ( points )
	prev = 0
	curr = 0
	for i in range ( N ) :
		temp = [ points [ i ] , points [ ( i + 1 ) % N ] , points [ ( i + 2 ) % N ] ]
		curr = CrossProduct ( temp )
		if ( curr != 0 ) :
			if ( curr * prev < 0 ) :
				return False
			else :
				prev = curr
	return True
if __name__ == ' _ _ main _ _ ' :
	points = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ]
	if ( isConvex ( points ) ) :
		print ( " Yes " )
	else :
		print ( " No " )