Page

**1**of**1**### A+B+C+D=0 from vector + dist

Posted:

**Tue Jan 20, 2015 5:31 am**How can I get the A+B+C+D=0 plane formula from a Quake mplane_t normal and dist?

I am assuming the mplane_t normal vectors are perpendicular to the plane as one would expect.

I am assuming the mplane_t normal vectors are perpendicular to the plane as one would expect.

### Re: A+B+C+D=0 from vector + dist

Posted:

**Tue Jan 20, 2015 11:04 am**A+B+C= -D ?

### Re: A+B+C+D=0 from vector + dist

Posted:

**Tue Jan 20, 2015 11:14 am**its best expressed as A*x + B*y + C*z - D = 0

some useful formulas:

distfromplane = DotProduct (plane->normal, point) - plane->dist;

plane->dist = DotProduct(plane->normal, pointonplane);

pointonplane = point - (distfromplane*plane->normal);

isinfront = distfromplane>0;

isbehind = distfromplane<0;

isfloatingpointprecisionmiraclethatyouhavetosomehowrollintoonesideyetstillallowsplayerstofallthroughcracks = distfromplane==0;

note that the distance is negated relative to more standard plane notation. in mathematics, the plane is generally two-sided. in quake, the normal faces directly forwards into empty space (unless the surface has SURF_PLANEBACK set, in which case the normal faces backwards - all 4 values are logically negated (or in the case of nodes, the two children are pre-swapped, avoiding the need for the engine to do anything special). note that the plane normals in a quake bsp are arranged to be primarily positive, reducing the total number of planes needed, and facilitating axial lookups).

for surfaces, the two tangents are normally available via the texture vector values, but note that these vectors are not kept strictly perpedicular to the normal, nor are they always normalized. because quake is weird and has annoying texture mapping, as well as texture scaling.

some useful formulas:

distfromplane = DotProduct (plane->normal, point) - plane->dist;

plane->dist = DotProduct(plane->normal, pointonplane);

pointonplane = point - (distfromplane*plane->normal);

isinfront = distfromplane>0;

isbehind = distfromplane<0;

isfloatingpointprecisionmiraclethatyouhavetosomehowrollintoonesideyetstillallowsplayerstofallthroughcracks = distfromplane==0;

note that the distance is negated relative to more standard plane notation. in mathematics, the plane is generally two-sided. in quake, the normal faces directly forwards into empty space (unless the surface has SURF_PLANEBACK set, in which case the normal faces backwards - all 4 values are logically negated (or in the case of nodes, the two children are pre-swapped, avoiding the need for the engine to do anything special). note that the plane normals in a quake bsp are arranged to be primarily positive, reducing the total number of planes needed, and facilitating axial lookups).

for surfaces, the two tangents are normally available via the texture vector values, but note that these vectors are not kept strictly perpedicular to the normal, nor are they always normalized. because quake is weird and has annoying texture mapping, as well as texture scaling.

### Re: A+B+C+D=0 from vector + dist

Posted:

**Tue Jan 20, 2015 7:20 pm**Thanks for info on the weirdnesses, especially since that information can only be known from experience and no one finds surprises any fun.

I spotted a couple of these in txqbsp.

I'm trying to do the opposite of that and draw the planes.

If I "cheated" I could use VectorVectors (like AngleVectors, except uses vectors) on a plane normal to get the side and up and then do some extra work to get a couple of points and use the 3 points to plane formula.

But that seems like a ton of calculations for something simple.

It seems like something intuitive and simple should be able to take the plane normal and get the A*x + B*y + C*z - D = 0.

I spotted a couple of these in txqbsp.

Spike wrote:pointonplane = point - (distfromplane*plane->normal);

I'm trying to do the opposite of that and draw the planes.

If I "cheated" I could use VectorVectors (like AngleVectors, except uses vectors) on a plane normal to get the side and up and then do some extra work to get a couple of points and use the 3 points to plane formula.

But that seems like a ton of calculations for something simple.

It seems like something intuitive and simple should be able to take the plane normal and get the A*x + B*y + C*z - D = 0.

### Re: A+B+C+D=0 from vector + dist

Posted:

**Tue Jan 20, 2015 8:20 pm**the problem with drawing a plane is that a plane is infinitely long.

if you make a guess at a tangent (rotate the axis or just hardcode something), you can crossproduct it with the normal and normalize for a real tangent. and then do it again for some bitangent too. of course, these vectors have no relation to any texturing, but hey...

then you can generate a quad by moving '0 0 0' along the plane's normal onto the plane then extend sideways to find your four points.

alternatively you can figure out which axis is the most significant for the plane, pick a set of 4 points aligned on that axis, and then push them to match the plane.

if you're drawing a brush, once you have a quad you can then clip that quad by the other planes (retaining only the stuff on the inside of the brush). the resulting clipped polygon is your brush's face.

if you make a guess at a tangent (rotate the axis or just hardcode something), you can crossproduct it with the normal and normalize for a real tangent. and then do it again for some bitangent too. of course, these vectors have no relation to any texturing, but hey...

then you can generate a quad by moving '0 0 0' along the plane's normal onto the plane then extend sideways to find your four points.

alternatively you can figure out which axis is the most significant for the plane, pick a set of 4 points aligned on that axis, and then push them to match the plane.

if you're drawing a brush, once you have a quad you can then clip that quad by the other planes (retaining only the stuff on the inside of the brush). the resulting clipped polygon is your brush's face.

### Re: A+B+C+D=0 from vector + dist

Posted:

**Wed Feb 21, 2018 1:01 am**Just want to say thanks to Spike for help with these kinds of things over the years.

I did some plane/point tests today and this reminded me of how I struggled with this kind of thing in the past.

I did some plane/point tests today and this reminded me of how I struggled with this kind of thing in the past.

### Re: A+B+C+D=0 from vector + dist

Posted:

**Wed Feb 21, 2018 6:29 pm**Spike is the pillar of this forum Practically everything of the very few things I know about programming is thanks to him.Baker wrote:Just want to say thanks to Spike for help with these kinds of things over the years.

Plus I always admire your study on Quake engine, Baker. Did you start learning C programming with the classic "rearrange my cd albums in alphabetically order" learning program or did you start tinkering with Quake engine as your first experience? I'm curious about it

### Re: A+B+C+D=0 from vector + dist

Posted:

**Mon Mar 05, 2018 1:11 pm**toneddu2000 wrote:Plus I always admire your study on Quake engine, Baker. Did you start learning C programming with the classic "rearrange my cd albums in alphabetically order" learning program or did you start tinkering with Quake engine as your first experience? I'm curious about it

I had an interest in C before interacting with mh or Spike or compiling an engine.

But I had assumed C was an unknowable language.

mh ended up prodding me quite a bit to engine code when I asked generic "engine what-ifs" at arm's length. And Spike always provided detailed answers I often would not immediately understand but may later re-read and understand.

Around 2011, an odd realization occurred to me. I knew C. Then I realized not only did I know C, but I knew C better than 80% of the people who claim to know C.

Then I was forced to realize the paradox that I had considered learning C impossible and that I was better than 80% of people that "know C".

Interesting? Well ... even now I feel if I think about that too hard I might accidentally unwind a causality paradox in the fabric of the universe that will destroy everything ... so I don't.

But yeah, fucked up for sure. How the fuck did that happen?

Decent minds don't want to know!

That being said, I would not know C if it were not for mh and Spike. And even more fucked up that I created "Quakespasm source base 0" before completely knowing how to code C (yeah, Quakespasm is not a fork of FitzQuake but of precisely of Baker FitzQuake 0.95 which I wrote in 6 hours to positively tweak Spirit by making a Linux version despite not having Linux, haha!). Let alone wrote modern ProQuake before knowing C with bits I picked up here and there and sheer determination.

(next topic before we cause universe to explode! It still makes no sense! We are making the Elder Gods very angry by discussing this inconsistency and right now I can tell I have mad them real, real mad If I say one more sentence, surely a lavaball will be hurled in my general direction by angry Chthon)

### Re: A+B+C+D=0 from vector + dist

Posted:

**Tue Mar 06, 2018 8:43 am**LOL! That happened to me the same way!(but with quakeC, instead!). Spike is like a philosopher: his words are never quite understandable the first time you hear them!Baker wrote:And Spike always provided detailed answers I often would not immediately understand but may later re-read and understand.

Wait a minute.. Are you the author of QuakeSpasm?!?Baker wrote:That being said, I would not know C if it were not for mh and Spike. And even more fucked up that I created "Quakespasm source base 0" before completely knowing how to code C (yeah, Quakespasm is not a fork of FitzQuake but of precisely of Baker FitzQuake 0.95 which I wrote in 6 hours to positively tweak Spirit by making a Linux version despite not having Linux, haha!)

Baker wrote:(next topic before we cause universe to explode! It still makes no sense! We are making the Elder Gods very angry by discussing this inconsistency and right now I can tell I have mad them real, real mad If I say one more sentence, surely a lavaball will be hurled in my general direction by angry Chthon)