The Wayback Machine - https://web.archive.org/web/20240928070511/https://www.geeksforgeeks.org/minimum-area-polygon-three-points-given/
Open In App

Minimum area of a Polygon with three points given

Last Updated : 13 Jul, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Given three points of a regular polygon(n > 3), find the minimum area of a regular polygon (all sides same) possible with the points given.
Examples: 

Input : 0.00 0.00
        1.00 1.00
        0.00 1.00
Output : 1.00
By taking point (1.00, 0.00) square is 
formed of side 1.0 so area = 1.00 .

One thing to note in question before we proceed is that the number of sides must be at least 4 (note n > 3 condition)..
Here, we have to find the minimum area possible for a regular polygon, so to calculate the minimum possible area, we need to calculate the required value of n. As the side length is not given, so we first calculate the circumradius of the triangle formed by the points. It is given by the formula 
R = abc / 4A 
Where a, b, c are the sides of the triangle formed and A is the area of the triangle. Here, the area of the triangle can be calculated by Heron’s Formula.
After calculating circumradius of the triangle, we calculate the area of the polygon by the formula 
A = nX ( sin(360/n) xr2 /2 )
Here r represents the circumradius of n-gon (regular polygon of n sides). 
But, first we have to calculate value of n . To calculate n we first have to calculate all the angles of triangle by the cosine formula 
cosA = ( b2+c2-a2 ) / 2bc 
cosB = ( a2+c2-b2 ) / 2ac 
cosC = ( a2+b2-c2 ) / 2ab 
Then, n is given by 
n = pi / GCD (A , B, C ) 
Where A, B and C are the angles of the triangle . After calculating n we substitute this value to the formula for calculating area of polygon .
Below is the implementation of the given approach :
 

C++




// CPP program to find minimum area of polygon of
// number of sides more than three with given three points.
#include <bits/stdc++.h>
using namespace std;
 
// assigning pi value to variable
const double pi = 3.14159265359;
 
// calculating gcd value of two double values .
double gcd(double x, double y)
{
    return fabs(y) < 1e-4 ? x : gcd(y, fmod(x, y));
}
 
// Calculating minimum area of polygon through this function .
double min_area_of_polygon(double Ax, double Ay, double Bx,
                            double By, double Cx, double Cy)
{
    double a, b, c, Radius, Angle_A, Angle_B, Angle_C,
                              semiperimeter, n, area;
 
    // calculating the length of the sides of the triangle
    // formed from given points a, b, c represents the
    // length of different sides of triangle .
    a = sqrt((Bx - Cx) * (Bx - Cx) + (By - Cy) * (By - Cy));
    b = sqrt((Ax - Cx) * (Ax - Cx) + (Ay - Cy) * (Ay - Cy));
    c = sqrt((Ax - Bx) * (Ax - Bx) + (Ay - By) * (Ay - By));
 
    // here we have calculated the semiperimeter of a triangle .
    semiperimeter = (a + b + c) / 2;
 
    // Now from the semiperimeter area of triangle is derived
    // through the heron's formula .
    double area_triangle = sqrt(semiperimeter * (semiperimeter - a)
                                * (semiperimeter - b)
                                * (semiperimeter - c));
 
    // thus circumradius of the triangle is derived from the
    // sides and area of the triangle calculated .
    Radius = (a * b * c) / (4 * area_triangle);
 
    // Now each angle of the triangle is derived from the sides
    // of the triangle .
    Angle_A = acos((b * b + c * c - a * a) / (2 * b * c));
    Angle_B = acos((a * a + c * c - b * b) / (2 * a * c));
    Angle_C = acos((b * b + a * a - c * c) / (2 * b * a));
 
    // Now n is calculated such that area is minimum for
    // the regular n-gon .
    n = pi / gcd(gcd(Angle_A, Angle_B), Angle_C);
 
    // calculating area of regular n-gon through the circumradius
    // of the triangle .
    area = (n * Radius * Radius * sin((2 * pi) / n)) / 2;
 
    return area;
}
 
int main()
{
    // three points are given as input .
    double Ax, Ay, Bx, By, Cx, Cy;
    Ax = 0.00;
    Ay = 0.00;
    Bx = 1.00;
    By = 1.00;
    Cx = 0.00;
    Cy = 1.00;
 
    printf("%.2f", min_area_of_polygon(Ax, Ay, Bx, By, Cx, Cy));
    return 0;
}


Java




// Java program to find minimum
// area of polygon of number of
// sides more than three with
// given three points.
class GFG{
 
// Assigning pi value to variable
static double pi = 3.14159265359;
       
public static double fmod(double a,
                          double b)
{
  int result = (int) Math.floor(a / b);
  return a - result * b;
}
     
// calculating gcd value of
// two double values .
public static double gcd(double x,
                         double y)
{
  return Math.abs(y) < 1e-4 ? x :
         gcd(y, fmod(x, y));
}
       
// Calculating minimum area of polygon through this function .
public static double min_area_of_polygon(double Ax, double Ay,
                                         double Bx, double By,
                                         double Cx, double Cy)
{
  double a, b, c, Radius, Angle_A, Angle_B, Angle_C, 
         semiperimeter, n, area;
 
  // Calculating the length of the sides
  // of the triangle formed from given
  /// points a, b, c represents the 
  // length of different sides of triangle .
  a = Math.sqrt((Bx - Cx) * (Bx - Cx) +
                (By - Cy) * (By - Cy));
  b = Math.sqrt((Ax - Cx) * (Ax - Cx) +
                (Ay - Cy) * (Ay - Cy));
  c = Math.sqrt((Ax - Bx) * (Ax - Bx) +
                (Ay - By) * (Ay - By));
 
  // Here we have calculated the
  // semiperimeter of a triangle .
  semiperimeter = (a + b + c) / 2;
 
  // Now from the semiperimeter area
  // of triangle is derived
  // through the heron's formula .
  double area_triangle = Math.sqrt(semiperimeter *
                                  (semiperimeter - a) *
                                  (semiperimeter - b) *
                                  (semiperimeter - c));
 
  // Thus circumradius of the triangle
  // is derived from the sides and
  // area of the triangle calculated .
  Radius = (a * b * c) / (4 * area_triangle);
 
  // Now each angle of the triangle
  // is derived from the sides
  // of the triangle .
  Angle_A = Math.acos((b * b + c * c - a * a) /
                      (2 * b * c));
  Angle_B = Math.acos((a * a + c * c - b * b) /
                      (2 * a * c));
  Angle_C = Math.acos((b * b + a * a - c * c) /
                      (2 * b * a));
 
  // Now n is calculated such that
  // area is minimum for the regular n-gon .
  n = pi / gcd(gcd(Angle_A, Angle_B), Angle_C);
 
  // calculating area of regular n-gon
  // through the circumradius of the triangle .
  area = (n * Radius * Radius *
          Math.sin((2 * pi) / n)) / 2;
 
  return area;
}
   
// Driver code
public static void main(String[] args)
{
  // Three points are given as input .
  double Ax, Ay, Bx, By, Cx, Cy;
  Ax = 0.00;
  Ay = 0.00;
  Bx = 1.00;
  By = 1.00;
  Cx = 0.00;
  Cy = 1.00;
  System.out.println(String.format("%.2f",
                     min_area_of_polygon(Ax, Ay,
                                         Bx, By,
                                         Cx, Cy)));
}
}
 
// This code is contributed by divyeshrabadiya07


Python3




# Python3 program to find minimum area of
# polygon of number of sides more than three
# with given three points.
 
# from math lib import every function
from math import *
 
# assigning pi value to variable
pi = 3.14159265359
 
# calculating gcd value of two double values .
def gcd(x, y) :
 
    if abs(y) < 1e-4 :
        return x
    else :
        return gcd(y, fmod(x, y))
 
 
# Calculating minimum area of polygon
# through this function .
def min_area_of_polygon(Ax, Ay, Bx,
                        By, Cx, Cy) :
 
    # calculating the length of the sides of
    # the triangle formed from given points
    # a, b, c represents the length of different
    # sides of triangle
    a = sqrt((Bx - Cx) * (Bx - Cx) +
             (By - Cy) * (By - Cy))
    b = sqrt((Ax - Cx) * (Ax - Cx) +
             (Ay - Cy) * (Ay - Cy))
    c = sqrt((Ax - Bx) * (Ax - Bx) +
             (Ay - By) * (Ay - By))
 
    # here we have calculated the semiperimeter
    # of a triangle .
    semiperimeter = (a + b + c) / 2
 
    # Now from the semiperimeter area of triangle
    # is derived through the heron's formula
    area_triangle = sqrt(semiperimeter *
                        (semiperimeter - a) *
                        (semiperimeter - b) *
                        (semiperimeter - c))
 
    # thus circumradius of the triangle is derived
    # from the sides and area of the triangle calculated
    Radius = (a * b * c) / (4 * area_triangle)
 
    # Now each angle of the triangle is derived
    # from the sides of the triangle
    Angle_A = acos((b * b + c * c - a * a) / (2 * b * c))
    Angle_B = acos((a * a + c * c - b * b) / (2 * a * c))
    Angle_C = acos((b * b + a * a - c * c) / (2 * b * a))
 
    # Now n is calculated such that area is
    # minimum for the regular n-gon
    n = pi / gcd(gcd(Angle_A, Angle_B), Angle_C)
 
    # calculating area of regular n-gon through
    # the circumradius of the triangle
    area = (n * Radius * Radius *
            sin((2 * pi) / n)) / 2
 
    return area
 
# Driver Code
if __name__ == "__main__" :
 
    # three points are given as input .
    Ax = 0.00
    Ay = 0.00
    Bx = 1.00
    By = 1.00
    Cx = 0.00
    Cy = 1.00
 
    print(round(min_area_of_polygon(Ax, Ay, Bx,
                                    By, Cx, Cy), 1))
 
# This code is contributed by Ryuga


C#




// C# program to find minimum
// area of polygon of number of
// sides more than three with
// given three points. 
using System;
using System.Collections.Generic;
 
class GFG
{
     
    // Assigning pi value to variable
    static double pi = 3.14159265359;
            
    static double fmod(double a, double b)
    {
      int result = (int) Math.Floor(a / b);
      return a - result * b;
    }
          
    // calculating gcd value of
    // two double values .
    static double gcd(double x, double y)
    {
      return Math.Abs(y) < 1e-4 ? x : gcd(y, fmod(x, y));
    }
            
    // Calculating minimum area of polygon through this function .
    static double min_area_of_polygon(double Ax, double Ay,
                                             double Bx, double By,
                                             double Cx, double Cy)
    {
      double a, b, c, Radius, Angle_A, Angle_B, Angle_C, 
             semiperimeter, n, area;
      
      // Calculating the length of the sides
      // of the triangle formed from given
      /// points a, b, c represents the 
      // length of different sides of triangle .
      a = Math.Sqrt((Bx - Cx) * (Bx - Cx) +
                    (By - Cy) * (By - Cy));
      b = Math.Sqrt((Ax - Cx) * (Ax - Cx) +
                    (Ay - Cy) * (Ay - Cy));
      c = Math.Sqrt((Ax - Bx) * (Ax - Bx) +
                    (Ay - By) * (Ay - By));
      
      // Here we have calculated the
      // semiperimeter of a triangle .
      semiperimeter = (a + b + c) / 2;
      
      // Now from the semiperimeter area
      // of triangle is derived
      // through the heron's formula .
      double area_triangle = Math.Sqrt(semiperimeter *
                                      (semiperimeter - a) *
                                      (semiperimeter - b) *
                                      (semiperimeter - c));
      
      // Thus circumradius of the triangle
      // is derived from the sides and
      // area of the triangle calculated .
      Radius = (a * b * c) / (4 * area_triangle);
      
      // Now each angle of the triangle
      // is derived from the sides
      // of the triangle .
      Angle_A = Math.Acos((b * b + c * c - a * a) /
                          (2 * b * c));
      Angle_B = Math.Acos((a * a + c * c - b * b) /
                          (2 * a * c));
      Angle_C = Math.Acos((b * b + a * a - c * c) /
                          (2 * b * a));
      
      // Now n is calculated such that
      // area is minimum for the regular n-gon .
      n = pi / gcd(gcd(Angle_A, Angle_B), Angle_C);
      
      // calculating area of regular n-gon
      // through the circumradius of the triangle .
      area = (n * Radius * Radius *
              Math.Sin((2 * pi) / n)) / 2;
      
      return area;
    }  
   
  // Driver code
  static void Main()
  {
      // Three points are given as input .
      double Ax, Ay, Bx, By, Cx, Cy;
      Ax = 0.00;
      Ay = 0.00;
      Bx = 1.00;
      By = 1.00;
      Cx = 0.00;
      Cy = 1.00;
      Console.WriteLine(String.Format("{0:0.00}", min_area_of_polygon(Ax, Ay,
                                             Bx, By,
                                             Cx, Cy)));
  }
}
 
// This code is contributed by divyeshrabadiya07


Javascript




<script>
// Javascript program to find minimum
// area of polygon of number of
// sides more than three with
// given three points.
 
 
// Assigning pi value to variable
let pi = 3.14159265359;
 
function fmod(a, b) {
  let result = Math.floor(a / b);
  return a - result * b;
}
 
// calculating gcd value of
// two double values .
function gcd(x, y) {
  return Math.abs(y) < 1e-4 ? x :
    gcd(y, fmod(x, y));
}
 
// Calculating minimum area of polygon through this function .
function min_area_of_polygon(Ax, Ay, Bx, By, Cx, Cy) {
  let a, b, c, Radius, Angle_A, Angle_B, Angle_C,
    semiperimeter, n, area;
 
  // Calculating the length of the sides
  // of the triangle formed from given
  /// points a, b, c represents the 
  // length of different sides of triangle .
  a = Math.sqrt((Bx - Cx) * (Bx - Cx) +
    (By - Cy) * (By - Cy));
  b = Math.sqrt((Ax - Cx) * (Ax - Cx) +
    (Ay - Cy) * (Ay - Cy));
  c = Math.sqrt((Ax - Bx) * (Ax - Bx) +
    (Ay - By) * (Ay - By));
 
  // Here we have calculated the
  // semiperimeter of a triangle .
  semiperimeter = (a + b + c) / 2;
 
  // Now from the semiperimeter area
  // of triangle is derived
  // through the heron's formula .
  let area_triangle = Math.sqrt(semiperimeter *
    (semiperimeter - a) *
    (semiperimeter - b) *
    (semiperimeter - c));
 
  // Thus circumradius of the triangle
  // is derived from the sides and
  // area of the triangle calculated .
  Radius = (a * b * c) / (4 * area_triangle);
 
  // Now each angle of the triangle
  // is derived from the sides
  // of the triangle .
  Angle_A = Math.acos((b * b + c * c - a * a) /
    (2 * b * c));
  Angle_B = Math.acos((a * a + c * c - b * b) /
    (2 * a * c));
  Angle_C = Math.acos((b * b + a * a - c * c) /
    (2 * b * a));
 
  // Now n is calculated such that
  // area is minimum for the regular n-gon .
  n = pi / gcd(gcd(Angle_A, Angle_B), Angle_C);
 
  // calculating area of regular n-gon
  // through the circumradius of the triangle .
  area = (n * Radius * Radius *
    Math.sin((2 * pi) / n)) / 2;
 
  return area;
}
 
function to_fixed(float, pre) {
  let x = new String(float).split(".")
  return x[0] + "." + x[1].slice(0, pre)
}
 
// Driver code
// Three points are given as input .
let Ax, Ay, Bx, By, Cx, Cy;
Ax = 0.00;
Ay = 0.00;
Bx = 1.00;
By = 1.00;
Cx = 0.00;
Cy = 1.00;
document.write(to_fixed(min_area_of_polygon(Ax, Ay, Bx, By, Cx, Cy), 2));
 
  // This code is contributed by Saurabh Jaiswal
</script>


Output: 

1.00

Time complexity : O(log(min(A,B,C)))

Auxiliary Space : O(1), since no extra space has been taken.



Previous Article
Next Article

Similar Reads

Ways to choose three points with distance between the most distant points <= L
Given a set of n distinct points x1, x2, x3... xn all lying on the X-axis and an integer L, the task is to find the number of ways of selecting three points such that the distance between the most distant points is less than or equal to L Note: Order is not important i.e the points {3, 2, 1} and {1, 2, 3} represent the same set of three points Exam
15+ min read
Check if given polygon is a convex polygon or not
Given 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, all interior angles are less than or equal to 18
9 min read
Check if the given point lies inside given N points of a Convex Polygon
Given 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 Input: N = 7, Points: {(1, 1), (2, 1), (3, 1), (4
15 min read
Polygon with maximum sides that can be inscribed in an N-sided regular polygon
Given a regular polygon of N sides, the task is to find the maximum sided polygon that can be inscribed inside the given polygon by joining non-adjacent vertices. Print -1, if no such polygon exist. Examples: Input: N = 8Output: 4Explanation:At most a 4 sided polygon can be inscribed inside the given 8-sided polygon as shown below: Input: N = 3Outp
3 min read
Area of a polygon with given n ordered vertices
Given ordered coordinates of a polygon with n vertices. Find the area of the polygon. Here ordered means that the coordinates are given either in a clockwise manner or anticlockwise from the first vertex to last.Examples : Input : X[] = {0, 4, 4, 0}, Y[] = {0, 0, 4, 4}; Output : 16 Input : X[] = {0, 4, 2}, Y[] = {0, 0, 4} Output : 8 We can compute
6 min read
Minimum number of points to be removed to get remaining points on one side of axis
We are given n points in a Cartesian plane. Our task is to find the minimum number of points that should be removed in order to get the remaining points on one side of any axis. Examples : Input : 4 1 1 2 2 -1 -1 -2 2 Output : 1 Explanation : If we remove (-1, -1) then all the remaining points are above x-axis. Thus the answer is 1. Input : 3 1 10
6 min read
Find three vertices in an N-sided regular polygon such that the angle subtended at a vertex by two other vertices is closest to A
Given an N-sided regular convex polygon and an angle A in degrees, the task is to find any 3 vertices i, j, and k, such that the angle subtended at vertex j by vertex i and k is closest to A. Note: Each vertex is numbered from 1 to N in an anticlockwise direction starting from any vertex. Examples: Input: N = 3, A = 15Output: 2 1 3Explanation:The g
7 min read
CSES Solutions - Polygon Lattice Points
Given a polygon, your task is to calculate the number of lattice points inside the polygon and on its boundary. A lattice point is a point whose coordinates are integers. The polygon consists of n vertices (x1,y1),(x2,y2),....,(xn,yn). The vertices (xi,yi) and (xi+1,yi+1) are adjacent for i=1,2,....,n-1, and the vertices (x1,y1) and (xn,yn) are als
9 min read
Find three element from given three arrays such that their sum is X | Set 2
Given three sorted integer arrays A[], B[] and C[], the task is to find three integers, one from each array such that they sum up to a given target value X. Print Yes or No depending on whether such triplet exists or not.Examples: Input: A[] = {2}, B[] = {1, 6, 7}, C[] = {4, 5}, X = 12 Output: Yes A[0] + B[1] + C[0] = 2 + 6 + 4 = 12Input: A[] = {2}
9 min read
Find three closest elements from given three sorted arrays
Given three sorted arrays A[], B[] and C[], find 3 elements i, j and k from A, B and C respectively such that max(abs(A[i] - B[j]), abs(B[j] - C[k]), abs(C[k] - A[i])) is minimized. Here abs() indicates absolute value. Example : Input : A[] = {1, 4, 10} B[] = {2, 15, 20} C[] = {10, 12} Output: 10 15 10Explanation: 10 from A, 15 from B and 10 from C
15+ min read
Check whether triangle is valid or not if three points are given
Given coordinates of three points in a plane P1, P2 and P3, the task is to check if the three points form a triangle or notExamples: Input: P1 = (1, 5), P2 = (2, 5), P3 = (4, 6) Output: YesInput: P1 = (1, 1), P2 = (1, 4), P3 = (1, 5) Output: No Approach: The key observation in the problem is three points form a triangle only when they don't lie on
9 min read
Equation of circle when three points on the circle are given
Given three coordinates that lie on a circle, (x1, y1), (x2, y2), and (x3, y3). The task is to find the equation of the circle and then print the centre and the radius of the circle. The equation of circle in general form is x² + y² + 2gx + 2fy + c = 0 and in radius form is (x - h)² + (y -k)² = r², where (h, k) is the centre of the circle and r is
11 min read
Find the point on X-axis from given N points having least Sum of Distances from all other points
Given an array arr[] consisting of N integers, denoting N points lying on the X-axis, the task is to find the point which has the least sum of distances from all other points. Example: Input: arr[] = {4, 1, 5, 10, 2} Output: (4, 0) Explanation: Distance of 4 from rest of the elements = |4 - 1| + |4 - 5| + |4 - 10| + |4 - 2| = 12 Distance of 1 from
11 min read
Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
A circle is given with k equidistant points on its circumference. 2 points A and B are given in the circle. Find the count of all obtuse angles (angles larger than 90 degree) formed from /_ACB, where C can be any point in circle other than A or B. Note : A and B are not equal. A < B. Points are between 1 and K(both inclusive). Examples : Input :
5 min read
Program to find Area of Triangle inscribed in N-sided Regular Polygon
Given the triangle inscribed in an N-sided regular polygon with given side length, formed using any 3 vertices of the polygon, the task is to find the area of this triangle. Examples: Input: N = 6, side = 10 Output: 129.904 Input: N = 8, side = 5 Output: 45.2665 Approach: Consider the 1st example: Given is a 6 sided regular polygon ABCDEF with a tr
6 min read
Area of largest Circle inscribe in N-sided Regular polygon
Given a regular polygon of N sides with side length a. The task is to find the area of the Circle which inscribed in the polygon. Note : This problem is mixed version of This and This Examples: Input: N = 6, a = 4 Output: 37.6801 Explanation: In this, the polygon have 6 faces and as we see in fig.1 we clearly see that the angle x is 30 degree so th
5 min read
Ratio of area of two nested polygons formed by connecting midpoints of sides of a regular N-sided polygon
Given an N-sided polygon, the task is to find the ratio of the area of the Nth to (N + 1)th N-sided regular nested polygons generated by joining the midpoints of the sides of the original polygon. Examples : Input: N = 3Output: 4.000000Explanation: Ratio of the length of the sides formed by joining the mid-points of the triangle with the length of
4 min read
Class 8 RD Sharma Solutions - Chapter 20 Area Of Trapezium And Polygon- Exercise 20.1 | Set 2
Chapter 20 Area Of Trapezium And Polygon- Exercise 20.1 | Set 1Question 12. The floor of a building consists of 3000 tiles which are rhombus shaped and each of its diagonals are 45 cm and 30 cm in length. Find the total cost of polishing the floor, if the cost per m2 is Rs. 4. Solution: As we know that, Area of rhombus = 1/2 × d1 × d2 Area of rhomb
7 min read
CSES Solution - Polygon Area
Your task is to calculate the area of a given polygon. The polygon consists of n vertices (x1,y1),(x2,y2),.....(xn,yn). The vertices (xi,yi) and (xi+1,yi+1) are adjacent for i=1,2,....,n-1, and the vertices (x1,y1) and (xn,yn) are also adjacent. Example: Input: vertices[] = {{1, 1}, {4, 2}, {3, 5}, {1, 4}}Output: 16 Input: vertices[] = {{1, 3}, {5,
5 min read
Area of the largest rectangle formed by lines parallel to X and Y axis from given set of points
Given an array arr[] consisting of N pair of integers representing coordinates of N points, the task is to find the area of the largest rectangle formed by straight lines drawn parallel to X and Y-axis from a given set of points. Examples: Input: arr[] = {{0, 0}, {1, 1}}Output: 1Explanation: The area of the largest rectangle is 1 formed by the coor
6 min read
Maximize area of triangle formed by points on sides of given rectangle
Given a rectangle [(x1, y1), (x2, y2)] denoting the coordinates of bottom-left corner and top-right corner whose sides are parallel to coordinates axes and N points on its perimeter (at least one on each side). The task is to maximize the area of a triangle formed by these points. Examples: Input: rectangle[][]= {{0, 0}, {6, 6}}, coordinates[][] =
10 min read
Number of quadruples where the first three terms are in AP and last three terms are in GP
Given an array arr[] of N integers. The task is to find the number of index quadruples (i, j, k, l) such that a[i], a[j] and a[k] are in AP and a[j], a[k] and a[l] are in GP. All the quadruples have to be distinct.Examples: Input: arr[] = {2, 6, 4, 9, 2} Output: 2 Indexes of elements in the quadruples are (0, 2, 1, 3) and (4, 2, 1, 3) and correspon
9 min read
Find three element from different three arrays such that a + b + c = sum
Given three integer arrays and a "sum", the task is to check if there are three elements a, b, c such that a + b + c = sum and a, b and c belong to three different arrays. Examples : Input : a1[] = { 1 , 2 , 3 , 4 , 5 }; a2[] = { 2 , 3 , 6 , 1 , 2 }; a3[] = { 3 , 2 , 4 , 5 , 6 }; sum = 9 Output : Yes 1 + 2 + 6 = 9 here 1 from a1[] and 2 from a2[] a
15+ min read
Number of triangles formed from a set of points on three lines
Given three integers m, n, and k that store the number of points on lines l1, l2, and l3 respectively that do not intersect. The task is to find the number of triangles that can possibly be formed from these set of points. Examples: Input: m = 3, n = 4, k = 5 Output: 205Input: m = 2, n = 2, k = 1 Output: 10 Approach: The total number of points are
5 min read
Program to check if three points are collinear
Given three points, check whether they lie on a straight (collinear) or notExamples : Input : (1, 1), (1, 4), (1, 5) Output : Yes The points lie on a straight line Input : (1, 5), (2, 5), (4, 6) Output : No The points do not lie on a straight line First approach Three points lie on the straight line if the area formed by the triangle of these three
10 min read
Find if a point lies inside, outside or on the circumcircle of three points A, B, C
Given four non-collinear points A, B, C, and P. The task is to find whether point P lies inside, outside or on the circumcircle formed by points A, B, and C.Examples Input: A = {2, 8}, B = {2, 1}, C = {4, 5}, P = {2, 4}; Output: Point (2, 4) is inside the circumcircle. Input: A = {2, 8}, B = {2, 1}, C = {4, 5}, P = {3, 0}; Output: Point (3, 0) lies
15+ min read
Steps required to visit M points in order on a circular ring of N points
Given an integer 'n', consider a circular ring containing 'n' points numbered from '1' to 'n' such that you can move in the following way : 1 -> 2 -> 3 -> ..... -> n -> 1 -> 2 -> 3 -> ...... Also, given an array of integers (of size 'm'), the task is to find the number of steps it'll take to get to every point in the array i
5 min read
Minimize the maximum distance between adjacent points after adding K points anywhere in between
Given an array arr[] of N integers representing the position of N points along a straight line and an integer K, the task is to find the minimum value of the maximum distance between adjacent points after adding K points anywhere in between, not necessarily on an integer position. Examples: Input: arr[] = {2, 4, 8, 10}, K = 1Output: 2Explanation: A
9 min read
Prime points (Points that split a number into two primes)
Given a n-digit number. Prime point is the index of the digit whose left and right side numbers are prime. Print all the prime points of the number. If no prime point exists print -1. Examples: Input : 2317 Output : 1 2 Explanation : Left and right side numbers of index point 1 are 2 and 17 respectively and both are primes. Left and right side numb
10 min read
Number of Integral Points between Two Points
Given two points p (x1, y1) and q (x2, y2), calculate the number of integral points lying on the line joining them. Input: x1 = 2, y1 = 2, x2 = 5, y2 = 5 Output: 2 Explanation: There are only 2 integral points on the line joining (2,2) and (5,5). The points are (3,3) and (4,4). Input: x1 = 1, y1 = 9, x2 = 8, y2 = 16 Output: 6 Explanation: There are
8 min read