Go Down

### Topic: How Do I Define A Slowly Tilting Plane On An LED Cube? (Warning, math ahead) (Read 1 time)previous topic - next topic

#### 012anonymousxyz ##### Jun 17, 2013, 02:11 amLast Edit: Jun 17, 2013, 02:15 am by 012anonymousxyz Reason: 1
Please watch this video starting at 0:43:
I'm attempting to recreate a plane of leds simply tilting from the xy-plane to the xz-plane.

I have a 4x4x4 cube.

Here is what I've figured out so far:
r = (0, 0, 0) + s(1, 0, 0) + t(0, y, z) where y is a variable going from 1->0 and z is a variable going from 0->1

I can define two functions to first increment z from 0 to 1 and then y from 1 to 0, but I don't think that is elegant. I was thinking that something like this should be done CONCURRENTLY using ONE incrementor variable that slowly reduces y and increases z at the same time.

So here is my function (written and being testing in java):
Code: [Select]
`    public static void main(String[] args){        double incrementor = 0.2; //0 -> 1;        for(int s = 0; s<4; s++){            for(int t=0; t<4; t++){                int x = s;                int y = (int)((t*(1-incrementor)) + 0.5); //1 -> 0                int z = (int)((t*incrementor)+ 0.5);     //0 - 1                System.out.println("Co-ordinates: (" + x + ", " + y + ", " + z + ")");            }         System.out.println();        }    }`

Now here is my problem: I can restrict the x values to range only from 0 to 3 by setting the for loop of the s parameter to go through 0 to 3. But notice the t variable. I noticed that when I set that to 0 to 3, the x and y values don't reach the length of the cube (i.e. y never equals 3). Furthermore, because of the rounding, the plane 'doubles' up. That is to say, at y=2, the leds at z=0 and z=1 are both on. That is not a plane

#### runaway_pancake #1
##### Jun 17, 2013, 03:06 am
Maybe if you deal with this in terms of a "plane" as a series of parallel lines.
http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
But, still, compromise is inevitable.
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

#### 012anonymousxyz #2
##### Jun 17, 2013, 03:33 am
Thanks a lot, I will read through that.
Meanwhile, I made this function. I think I was going through this wrong. I should not use an incrementor. I should stay based on fundamental mathematics and conform the code to the math. So what is the mathematical concept for a tilting plane? The angle!
So I'm attempting to find z based on the y value and an angle. So tanx = z/y, and z=ytanx.
Here is the code I came up with. As you see, I could not avoid the two different functions.
Code: [Select]
`   public static void computePlane(int angle){        if(angle>45){            for(int s=0; s<4; s++){                for(int t=0; t<4; t++){                    int x = s;                    int z = t;                    double y = z/(Math.tan(Math.toRadians(angle)));                    System.out.println("Co-ordinates: " + x + ", " + y + ", " + z + ")");                           }             System.out.println();            }        }else{            for(int s=0; s<4; s++){                for(int t=0; t<4; t++){                    int x = s;                    int y = t;                    double z = y*Math.tan(Math.toRadians(angle));                    System.out.println("Co-ordinates: " + x + ", " + y + ", " + z + ")");                }            System.out.println();            }        }    }`
This works like a charm except for the fact that it is impossible to avoid switching functions once the angle passes 45 because we want to increment the y value by 1 until we hit 45, and then we want to continue to increment z value by 1 until we hit 89.
Otherwise if I were to use the code in the else brackets for angle>45, z will have to be absolutely gigantic because y is still incrementing by 1. Hard to explain but you get it.
The next part is being able to define ANY plane somehow.
But I think I solved my main problem. I'm doing all this soley based on my own knowlege (I'm in gr12 calculus right now) so any link or advice to the proper method would be nice.

Once again, thanks for the link. I'm trying to get into graphics and the more knowledge of these algorithms and stuff the better!

#### fungus #3
##### Jun 17, 2013, 01:02 pm
Does math need a health warning these days?