Monday, 29 Nov 2021
Category: Geometric-Lines

Given N horizontal lines represented by an array position[][] of size N, where position[i] represents the ith horizontal line which has x-coordinates from position[i][0] to position[i][1] and an integer K, which represents the maximum number of vertical lines that can be drawn, the task is to check if N given lines can be intersected by […]

Given a 2D array arr[][], representing width of bricks of the same height present on a wall, the task is to find the minimum number of bricks that can be intersected by drawing a straight line from the top to the bottom of the wall.Note: A line is said to intersect a brick if it […]

#include using namespace std;  void check_position(int a, int b, int c, int d,                    int x1, int y1, int z1,                    int x2, int y2, int z2){        int value_1 = a * x1 + b * y1 + c * z1 + d;    int value_2 = a * x2 + b * y2 + c * z2 + d;          if ((value_1 > 0 […]

#include using namespace std;  double radius(int a, int b, int c){            int g = a / 2;    int f = b / 2;          if (g * g + f * f – c < 0)        return (-1);          return (sqrt(g * g + f * f - c));}  double centerDistanceFromLine(int a, int b,                              int i, int j,                              int k){        int g = a / 2;    int f […]

Check if two circles intersect such that the third circle passes through their points of intersections and centersGiven centres and the radii of three circles A, B, and C in the form of {X, Y, R}, where (X, Y) is the centre of the circle and R is the radius of that circle. The task […]

#include using namespace std;  void crossProduct(int vect_A[],                  int vect_B[],                  int cross_P[]){        cross_P[0]        = vect_A[1] * vect_B[2]          – vect_A[2] * vect_B[1];          cross_P[1]        = vect_A[2] * vect_B[0]          – vect_A[0] * vect_B[2];          cross_P[2]        = vect_A[0] * vect_B[1]          – vect_A[1] * vect_B[0];}  void checkCollinearity(int x1, int y1,                       int z1, int x2,                       int y2, int z2){        int A[3] = { x1, y1, z1 };    int B[3] = { x2, y2, z2 };          int cross_P[3];          crossProduct(A, B, cross_P);              if (cross_P[0] == […]

#include using namespace std;  void finalPosition(char a[], int b[],                   int M){                int n = 0, s = 0, e = 0, w = 0;              char p = ‘N’;          for (int i = 0; i < M; i++) {                          if (p == 'N') {              if (a[i] == 'U') {                p = 'N';                n = n + b[i];            }            else if (a[i] == 'D') {                p = 'S';                s = […]

Given two arrays X[] and Y[], representing points on X and Y number lines, such that every similar-indexed array element forms a line segment, i.e. X[i] and Y[i] forms a line segment, the task is to find the maximum number of line segments that can be selected from the given array. Examples: Input: X[] = […]