Check whether two convex regular polygon have same center or not Last Updated : 01 Nov, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Given two positive integers N and M which denotes the sides of the convex regular polygon where N < M, the task is to check whether polygons have the same center or not if N-sided polygon was inscribed in an M-sided polygon.Center of Polygon: Point inside a polygon which is equidistant from each vertex of the polygon. Examples: Input: N = 9, M = 3 Output: YES Explanation: Polygon of side 3 when inscribed in a polygon of side 9, then both polygons have same center.Input: N = 10, M = 3 Output: NO Explanation: Polygon of side 3 when inscribed in a polygon of side 10, then both polygons don't have same center. Approach: The key observation in this problem is that when M % N == 0, that means the sides of N-sided polygon equally covers the sides of M-sided polygon, which means both the polygons have same center.Algorithm: Check if M is divisible by N, If yes then both the polygons have same center.Otherwise both polygons have the different centers.Below is the implementation of the above approach: C++ // C++ implementation to check whether // two convex polygons have same center #include<bits/stdc++.h> using namespace std; // Function to check whether two convex // polygons have the same center or not int check(int n, int m){ if (m % n == 0){ cout << "YES"; } else{ cout << "NO"; } return 0; } // Driver Code int main() { int n = 5; int m = 10; check(n, m); return 0; } Java // Java implementation to check whether // two convex polygons have same center class GFG{ // Function to check whether two convex // polygons have the same center or not static int check(int n, int m){ if (m % n == 0){ System.out.print("YES"); } else{ System.out.print("NO"); } return 0; } // Driver Code public static void main(String[] args) { int n = 5; int m = 10; check(n, m); } } // This code is contributed by sapnasingh4991 Python3 # Python3 implementation to check whether # two convex polygons have same center # Function to check whether two convex # polygons have the same center or not def check(n, m): if (m % n == 0): print("YES") else: print("NO") # Driver Code n = 5 m = 10 check(n, m) # This code is contributed by mohit kumar 29 C# // C# implementation to check whether // two convex polygons have same center using System; class GFG{ // Function to check whether two convex // polygons have the same center or not static int check(int n, int m){ if (m % n == 0){ Console.Write("YES"); } else{ Console.Write("NO"); } return 0; } // Driver Code public static void Main(String[] args) { int n = 5; int m = 10; check(n, m); } } // This code is contributed by Rajput-Ji JavaScript <script> // Javascript implementation to check whether // two convex polygons have same center // Function to check whether two convex // polygons have the same center or not function check(n, m) { if (m % n == 0) { document.write("YES"); } else { document.write("NO"); } return 0; } // Driver code var n = 5; var m = 10; check(n, m); // This code is contributed by Kirti </script> OutputYES Performance Analysis: Time Complexity: O(1).Auxiliary Space: O(1). Comment More infoAdvertise with us Next Article Minimum Enclosing Circle S sauravlal15 Follow Improve Article Tags : DSA Similar Reads Convex Hull Algorithm The Convex Hull Algorithm is used to find the convex hull of a set of points in computational geometry. The convex hull is the smallest convex set that encloses all the points, forming a convex polygon. This algorithm is important in various applications such as image processing, route planning, and 8 min read Convex Hull using Divide and Conquer Algorithm In computational geometry, a convex hull is the smallest convex polygon that contains a given set of points. It is a fundamental concept with applications in various fields such as computer graphics, robotics, and image processing. Importance of Convex Hull:Convex hulls are important in computationa 15 min read Convex Hull using Jarvis' Algorithm or Wrapping Given a set of points in the plane. the convex hull of the set is the smallest convex polygon that contains all the points of it.We strongly recommend to see the following post first. How to check if two given line segments intersect?The idea of Jarvis's Algorithm is simple, we start from the leftmo 13 min read Convex Hull using Graham Scan A convex hull is the smallest convex polygon that contains a given set of points. It is a useful concept in computational geometry and has applications in various fields such as computer graphics, image processing, and collision detection.A convex polygon is a polygon in which all interior angles ar 15+ min read Convex Hull | Monotone chain algorithm Given a set of points, the task is to find the convex hull of the given points. The convex hull is the smallest convex polygon that contains all the points. Please check this article first: Convex Hull | Set 1 (Jarvisâs Algorithm or Wrapping) Examples: Input: Points[] = {{0, 3}, {2, 2}, {1, 1}, {2, 11 min read Quickhull Algorithm for Convex Hull Given a set of points, a Convex hull is the smallest convex polygon containing all the given points. Input : points[] = {{0, 3}, {1, 1}, {2, 2}, {4, 4}, {0, 0}, {1, 2}, {3, 1}, {3, 3}};Output : The points in convex hull are: (0, 0) (0, 3) (3, 1) (4, 4)Input : points[] = {{0, 3}, {1, 1}Output : Not P 14 min read Problems on Convex HullDynamic Convex hull | Adding Points to an Existing Convex HullGiven a convex hull, we need to add a given number of points to the convex hull and print the convex hull after every point addition. The points should be in anti-clockwise order after addition of every point. Examples: Input : Convex Hull : (0, 0), (3, -1), (4, 5), (-1, 4) Point to add : (100, 100) 15 min read Deleting points from Convex HullGiven a fixed set of points. We need to find convex hull of given set. We also need to find convex hull when a point is removed from the set. Example: Initial Set of Points: (-2, 8) (-1, 2) (0, 1) (1, 0) (-3, 0) (-1, -9) (2, -6) (3, 0) (5, 3) (2, 5) Initial convex hull:- (-2, 8) (-3, 0) (-1, -9) (2, 15+ min read Perimeter of Convex hull for a given set of pointsGiven n 2-D points points[], the task is to find the perimeter of the convex hull for the set of points. A convex hull for a set of points is the smallest convex polygon that contains all the points. Examples: Input: points[] = {{0, 3}, {2, 2}, {1, 1}, {2, 1}, {3, 0}, {0, 0}, {3, 3}} Output: 12 Inpu 10 min read Check if the given point lies inside given N points of a Convex PolygonGiven coordinates of the N points of a Convex Polygon. The task is to check if the given point (X, Y) lies inside the polygon. Examples:Input: N = 7, Points: {(1, 1), (2, 1), (3, 1), (4, 1), (4, 2), (4, 3), (4, 4)}, Query: X = 3, Y = 2 Below is the image of plotting of the given points: Output: YES 15 min read Tangents between two Convex PolygonsGiven two convex polygons, we aim to identify the lower and upper tangents connecting them. As shown in the figure below, TRL and TLR represent the upper and lower tangents, respectively. Examples: Input: First Polygon : [[2, 2], [3, 3], [5, 2], [4, 0], [3, 1]] Second Polygon : [[-1, 0], [0, 1], [1, 15 min read Check if given polygon is a convex polygon or notGiven a 2D array point[][] 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, 9 min read Check whether two convex regular polygon have same center or notGiven two positive integers N and M which denotes the sides of the convex regular polygon where N < M, the task is to check whether polygons have the same center or not if N-sided polygon was inscribed in an M-sided polygon.Center of Polygon: Point inside a polygon which is equidistant from each 3 min read Minimum Enclosing CirclePrerequisites: Equation of circle when three points on the circle are given, Convex HullGiven an array arr[][] containing N points in a 2-D plane with integer coordinates. The task is to find the centre and the radius of the minimum enclosing circle(MEC). A minimum enclosing circle is a circle in wh 15+ min read How to Highlight Groups with Convex Hull in ggplot2 in R? In this article, we are going to see how to highlight groups with the convex hull in ggplot2 using R Programming Language. Convex hull polygon refers to the draw a line bounding box around the outermost points in each group. Creating scatterplot for demonstration Here we will use the iris dataset t 2 min read Like