Search code examples
c++mathlinear-algebraglm-math

How to get plane-vertices by a point and normal


I'm having a point p and a normal n (in 3d space). I want to calculate 4 vertex-points which are lying on the plane which is perpendicular to the normal and lies on the point p.

The vertices should form a rectangle and p should be the center of this rectangle.

enter image description here


Solution

  • One very useful tool is the cross product (from high school analytic geometry). This takes as an input an ordered pair of 3-dimensional vectors v and w, and produces a 3-dimensional vector vxw perpendicular to both, whose length is the area of the parallelogram whose sides are v and w, hence which is nonzero when v and w are not parallel. Implement the cross product yourself, or find it in a vector library, or look at this question.

    Given n, choose a vector v that is not parallel. nxv is perpendicular to n. Normalize this to get a unit vector u1 perpendicular to n. nxu1 is perpendicular to both n and u1. Normalize this to get u2. The points p+-u1, p+-u2 form a square with side length sqrt(2) whose center is p.

    It is natural to want to have a way to choose the points continuously. This is impossible even if you restrict to unit vectors n by the Hairy Ball Theorem. You have to allow a discontinuous choice of v. For example, you could use v = (1,0,0) unless n is a nonzero multiple of (1,0,0), and then use v = (0,1,0) there.