#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# how to program a simple wireframe cube with 3d maths (without box) only lines or vertexes ??

i would like to know the code of a 3D wireframe cube, without using any help like box etc. only the 3D Translation matrixes...thanks a lot for helping. martinpla

• draw diagrams.

a cube has 8 corners. work out the coordinates for these (in 3 dimensions) and stick them in an array, call it vertices.

then work out which corners are connected to which other corners. put this into another array, call it edges.

in draw() loop over the edges array picking out the pairs of points. look up each of these points in the vertices table. draw a line from the one to the other.

• ``````// the points
PVector[] vertices = new PVector ;

// the connecting lines
// e.g. edge 1 goes from vertices edgesFrom to edgesTo
int[] edgesFrom = new int ;
int[] edgesTo = new int ;

void setup() {
size(900, 790, OPENGL);
background(0);
vertices=new PVector (100, 100, 100);
} // func

void draw() {
background(0);

//  use for loop i and line (x1,y1,z1, x2,y2,z2);  here
//  with float x1 = vertices [ edgesFrom [i] ].x;
} // func
//
``````
• Hi Koogs, Hi Chrisir, would it be possible to get the whole code ? i am a beginner and i need more help in this topic...many thanks in advance, martinpla

• One way to approach this problem is to:

1. begin by creating your own square. can you solve that problem first? now you have 4 out of 8 points and 4 of 12 edges.
2. now create a second square which is a side-length above the first square. can you draw the two squares? now you have all 8 points and 8 out of 12 edges
3. finally, connect the four pairs of points vertically. now you have all 12 edges.

This is more or less the way I would do it if I was using toothpicks and glue.

• Naive approach:

Array of pvector named points or corners

Store 8 Points here each with its 3D position

2 parallel Array of int named from and to that hold the indexes(!) of first array. For loop over from and to and show lines:

``````for....

line(points[from[i]].x, points[from[i]].y, ...,

points[to[i]].x, ....
``````

Using 3D line command with 6 Parameters