Category: Geometric-Lines

Check if N given lines can be intersected by K vertical 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 […]

Continue Reading

Minimum number of bricks that can be intersected

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 […]

Continue Reading

Determine position of two points with respect to a 3D plane

#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 […]

Continue Reading

Length of intercept cut off from a line by a Circle

#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 […]

Continue Reading

Check if two vectors are collinear or not

#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] == […]

Continue Reading

Displacement from origin after N moves of given distances in specified directions

  #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 = […]

Continue Reading

Maximize count of intersecting line segments

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[] = […]

Continue Reading