The Wayback Machine - https://web.archive.org/web/20240701190851/https://www.geeksforgeeks.org/binary-space-partitioning/
Open In App

Binary Space Partitioning

Last Updated : 30 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Binary Space Partitioning is implemented for recursively subdividing a space into two convex sets by using hyperplanes as partitions. This process of subdividing gives rise to the representation of objects within the space in the form of tree data structure known as BSP Tree.
Binary space partitioning arose in the context of 3D computer graphics in 1969, where the structure of a BSP tree allows for spatial information about the objects in a scene that is useful in rendering, such as objects being ordered from front-to-back with respect to a viewer at a given location, to be accessed rapidly.

Needs of Binary Space Partitioning

Binary space partitioning arose from the computer graphics need to rapidly draw three-dimensional scenes composed of polygons. A simple way to draw such scenes is the painter’s algorithm, which produces polygons in order of distance from the viewer, back to front, painting over the background, and previous polygons with each closer object. This approach has two disadvantages: the time required to sort polygons in back to front order, and the possibility of errors in overlapping polygons. Fuchs and co-authors showed that constructing a BSP tree solved both of these problems by providing a rapid method of sorting polygons with respect to a given viewpoint (linear in the number of polygons in the scene) and by subdividing overlapping polygons to avoid errors that can occur with the painter’s algorithm.

Overview of BSP

Binary space partitioning is treated as a generic process of recursively dividing a scene into two until the partitioning satisfies one or more requirements. It can be viewed as a generalization of other spatial tree structures such as k-d trees and quadtrees, one where hyperplanes that partition space may have any orientation instead of being aligned with the coordinate axes as they are in k-d trees or quadtree.
When implemented in computer graphics to render scenes composed of planar polygons, the partitioning planes are frequently selected to coincide with the planes defined by polygons in the scene. The specific choice of partitioning plane and criterion for completing the partitioning process varies depending on the purpose of the BSP tree.
For example: In computer graphics rendering, the scene is divided until and unless each node of the BSP tree consists of only polygons that can render in arbitrary order. When back-face culling is implemented, each node, therefore, consists of a convex set of polygons, whereas when rendering double-sided polygons, each node of the BSP tree consists of only polygons in a single plane.

Algorithm of generating a BSP Tree from a list of polygons

  • Select a polygon P from the list.
  • Make a node N in the BSP tree, and add P to the list of polygons at that node.
  • For each other polygon in the list:
    • If that polygon is wholly in front of the plane containing P, move that polygon to the list of nodes in front of P.
    • If that polygon is wholly behind the plane containing P, move that polygon to the list of nodes behind P.
    • If that polygon is intersected by the plane containing P, split it into two polygons and move them to the respective lists of polygons behind and in front of P.
    • If that polygon lies in the plane containing P, add it to the list of polygons at node N.
  • Apply this algorithm to the list of polygons in front of P.
  • Apply this algorithm to the list of polygons behind P.

Disadvantage of BSP

  • Generating a BSP tree can be time-consuming.
  • BSP does not solve the problem of visible surface determination.

Uses of BSP

  • It is used in collision detection in 3D video games and robotics.
  • It is used in ray tracing
  • It is involved in the handling of complex spatial scenes.

Previous Article
Next Article

Similar Reads

Binary String Partitioning
Given a Binary String S consisting of N bits, integers K and D. The task is to determine whether the maximum absolute difference among all K disjoint strings in S can be made less than D. Note: Some of the K strings can be empty, and each character of S can only belong to one of the K strings Examples: Input: N = 6, K = 2, D = 5, S = "110001"Output
5 min read
What is the difference between Auxiliary space and Space Complexity?
Space complexity and Auxiliary space are two of the most often confused and interchangeably used terms when talking about the space complexity of a certain algorithm: Auxiliary Space: The extra space that is taken by an algorithm temporarily to finish its workSpace Complexity: Space complexity is the total space taken by the algorithm with respect
4 min read
Minimize the cost of partitioning an array into K groups
Given an array arr[] and an integer K, the task is to partition the array into K non-empty groups where each group is a subarray of the given array and each element of the array is part of only one group. All the elements in a given group must have the same value. You can perform the following operation any number of times: Choose an element from t
15+ min read
Three way partitioning using Dutch National Sort Algorithm(switch-case version) in Java
Given an array list arr and values lowVal and highVal. The task is to partition the array around the range such that the array List is divided into three parts. 1) All elements smaller than lowVal come first.2) All elements in range lowVal to highVVal come next.3) All elements greater than highVVal appear in the end.The individual elements of three
4 min read
Javascript Program For Partitioning A Linked List Around A Given Value And Keeping The Original Order
Given a linked list and a value x, partition it such that all nodes less than x come first, then all nodes with a value equal to x, and finally nodes with a value greater than or equal to x. The original relative order of the nodes in each of the three partitions should be preserved. The partition must work in place.Examples: Input: 1->4->3-
4 min read
Three way partitioning of an Array without changing the relative ordering
Given an array and a range [lowVal, highVal], partition the array around the range such that the array is divided into three parts. All elements smaller than lowVal come first. All elements in range lowVal to highVal come next. All elements greater than highVVal appear in the end. The relative ordering of numbers shouldn't be changed. Examples: Inp
9 min read
Find maximum subset sum formed by partitioning any subset of array into 2 partitions with equal sum
Given an array A containing N elements. Partition any subset of this array into two disjoint subsets such that both the subsets have an identical sum. Obtain the maximum sum that can be obtained after partitioning. Note: It is not necessary to partition the entire array, that is any element might not contribute to any of the partition. Examples: In
15+ min read
POTD Solutions | 24 Oct’ 23 | Palindromic Partitioning
View all POTD Solutions Welcome to the daily solutions of our PROBLEM OF THE DAY (POTD). We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Dynamic Programming but will also help you build up problem-solving skills. We recommend you to try this
6 min read
String Partitioning for Character Equality
Given a string S of size N, the task is to divide the given string into two non-empty strings s1 and s2 such that the number of distinct characters in s1 is equal to s2. Examples: Input: s = "aacaba"Output: 2Explanation: => Dividing s into s1 and s2 as ("aac", "aba"), the left string contains 2 distinct letters, and the right string also contain
7 min read
Clustering/Partitioning an array such that sum of square differences is minimum
Given an array of n numbers and a number k. We need to divide the array into k partitions (clusters) of the same or different lengths. For a given k, there can be one or more ways to make clusters (partitions). We define a function Cost(i) for the ith cluster, as the square of the difference between its first and last element. If the current cluste
15 min read
three90RightbarBannerImg