# Sort the 6 sides of a cube

**URL:** https://forum.kirupa.com/t/sort-the-6-sides-of-a-cube/329783
**Category:** flash
**Created:** [October 15, 2012, 5:37pm UTC](https://forum.kirupa.com/t/sort-the-6-sides-of-a-cube/329783 "2012-10-15T17:37:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Tompa](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@Tompa](https://forum.kirupa.com/u/Tompa)
#### Post date: [October 15, 2012, 5:37pm UTC](https://forum.kirupa.com/t/sort-the-6-sides-of-a-cube/329783/1 "2012-10-15T17:37:32Z")

</div>

I’ve been playing around with some 3D in flash lately and I’ve rendered every mesh by only showing their sides _(lineTo etc…)_. But now I want to show real fills on the sides, and not just lines.

This is how it looks like at the moment:  
 ![](http://forum.kirupa.com/uploads/kirupa/6639/77ae124106a187c8.jpg)

This does not look good, only the green polygon is placed right!  
I’m creating each side of the cube with this class:

```auto
public class Poly {        
    public var v1:Vertex, v2:Vertex, v3:Vertex, v4:Vertex;
        public function Poly(v1:Vertex, v2:Vertex, v3:Vertex, v4:Vertex) {
            this.v1 = v1; this.v2 = v2; this.v3 = v3; this.v4 = v4; 
        }
    }

```

And this is the Vertex-class:

```auto
public class Vertex {        
    public var X:Number, Y:Number, Z:Number;
        public function Vertex(X:Number, Y:Number, Z:Number) {
            this.X = X; this.Y = Y; this.Z = Z;
        }

        public function rotateX(a:Number):Vertex {
            var radian:Number = a * (Math.PI / 180);
            var Y:Number = (this.Y * Math.cos(radian)) - (this.Z * Math.sin(radian));
            var Z:Number = (this.Y * Math.sin(radian)) + (this.Z * Math.cos(radian));
            return new Vertex(X, Y, Z);
        }
        public function rotateY(a:Number):Vertex {
            var radian:Number = a * (Math.PI / 180);
            var Z:Number = (this.Z * Math.cos(radian)) - (this.X * Math.sin(radian));
            var X:Number = (this.Z * Math.sin(radian)) + (this.X * Math.cos(radian));
            return new Vertex(X, Y, Z);
        }
        public function rotateZ(a:Number):Vertex {
            var radian:Number = a * (Math.PI / 180);
            var X:Number = (this.X * Math.cos(radian)) - (this.Y * Math.sin(radian));
            var Y:Number = (this.X * Math.sin(radian)) + (this.Y * Math.cos(radian));
            return new Vertex(X, Y, Z);
        }
    }

```

I’m totally clueless on how to sort these polygons right, so \*\*any \*\*tips or help is really appreciated!:facepalm:

_~Tompa_
