VOOZH about

URL: https://www.geeksforgeeks.org/dsa/check-if-given-polygon-is-a-convex-polygon-or-not/

⇱ Check if given polygon is a convex polygon or not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if given polygon is a convex polygon or not

Last Updated : 23 Jul, 2025

Given a 2D arraypoint[][] with each row of the form {X, Y}, representing the co-ordinates of a polygon in either clockwise or counterclockwise sequence, the task is to check if the polygon is a convex polygon or not. If found to be true, then print "Yes" . Otherwise, print "No".

In a convex polygon, all interior angles are less than or equal to 180 degrees

Examples:

Input: arr[] = { (0, 0), (0, 1), (1, 1), (1, 0) } 
Output: Yes 
Explanation:

👁 Image


Since all interior angles of the polygon are less than 180 degrees. Therefore, the required output is Yes.

Input : arr[] = {(0, 0), (0, 10), (5, 5), (10, 10), (10, 0)} 
Output : No 
Explanation:

👁 Image


Since all interior angles of the polygon are not less than 180 degrees. Therefore, the required output is No.

Approach: Follow the steps below to solve the problem:

  • Traverse the array and check if direction of cross product of any two adjacent sides of the polygon are same or not. If found to be true, then print "Yes".
  • Otherwise, print "No"

Below is the implementation of the above approach:


Output
Yes

Time Complexity: O(N)
Auxiliary Space:O(1)

Comment
Article Tags: