0

What is an equation to determine if a 3d point (x,y,z) is within a rectangular prism on a cartesian coordinate system? I want to check if a point is inside a rectangular prism.

e.g. the equation for a 2d rectangle is |x+y|+|x-y|<=2. This equation is based on Cobold's question here and the work is shown there. An equation like this is much more efficient and simple than a big set of inequalities comparing each coordinate of the point to the minimum and maximum coordinates of the rectangular prism in that dimension

  • Welcome to MSE. Please read this text about how to ask a good question. – José Carlos Santos Feb 13 '22 at 02:18
  • This question is very unclear. First you say "within a rectangular prism", then "inside a rectangle", then you give a formula for a point that is on the perimeter of a square in a Cartesian plane. Meanwhile most people would just compare each coordinate of the point to the minimum and maximum coordinates of the rectangular prism in that dimension. – David K Feb 15 '22 at 14:09
  • 1
    Do you really call "big set" a set of 6 inequations ? Notice that your absolute values are comparisons in disguise, so that your test for a square centered at the origin already counts 3 of them. Your "much more efficient and simple" is a complete overstatement. –  Feb 15 '22 at 15:56
  • To generalize your formula so it suits any rectangle with sides parallel to the axis, you would need to introduce a coefficient to multiply at least one of the coordinates in each absolute value (in order to allow rectangles that are not square) and you would need to add constants inside each absolute value in order to allow rectangles not centered at the origin. Also you need formulas to produce the coefficient and constants from the coordinates of the rectangular prism if this is to be a general method. – David K Feb 15 '22 at 18:12
  • The reason the sum of absolute values works for a square is that the sum of absolute values in $n$ dimensions gives you a "cross" polytope, which in 2D is a square rotated $45^\circ$. By taking $x+y$ and $x-y$ instead of $x$ and $y$ you rotate the square parallel to the axes. In 3D the cross polytope is an octahedron, which will not become a cube via any rotation. – David K Feb 15 '22 at 18:15

1 Answers1

0

The equation of a cube of side $2$ centered at the origin is

$$\|P\|_\infty\le1$$ where $\|.\|_\infty$ denotes the maximum norm. This works in any dimensions. https://en.wikipedia.org/wiki/Lp_space#The_p-norm_in_finite_dimensions