In the following code, I expect to see two quads displayed on the canvas, but only the blue one shows up, and it shows up with a diagonal line between its two vertexes.
This appears to be a bug in p5.js
According to the documentation the last two parameters are optional but your code works if you add them. See code below
The only way to do this is to turn off the stroke (See code below). In p5.js the quad is drawn as 2 triangles hence the diagonal line. It is not usual to draw quads in 3D because all four vertices should lie in the same plane and that can’t be guaranteed. On the other hand a triangle has three vertices and they will always be in the same plane.
Thank you! May I suggest that when the four vertices happen to lie in the same plane (which you can detect), you don’t use 2 triangles but use a quadrilateral instead? Perhaps even better, don’t draw the shared edge between the 2 triangles with stroke on.
My understanding is that WEBGL does not support drawing quadrilaterals - you can see the drawing modes here. The quad(...) method in p5.js is a convenience method to make it easier for programmers to draw quadrilaterals in WEBGL and under the hood draws 2 triangles.
To determine whether 4 vertices lie in a plane is easy if they are axis-aligned as in your diagram (all on same z plane) but computationally expensive when not aligned.
In WEBGL either the stroke is on or off for the whole shape so to avoid the diagonal you would draw the triangles without stroke and then separately draw the 4 outside edges. Again not a good solution.
I would not recommend using stroke in WEBGL because if it is like OpenGL is has a serious effect on performance. OpenGL is optimized to draw borderless filled triangles.