Accessing vector element

OpenSCAD does not support manipulate variables like Python or other programming languages yet. Or I haven’t found how to do it.

V = 
[
     // 1st row  
    [0, [0, 0, 19.69]],                  // 0
    
    // 2nd row
    // [10.3516, 0, -10.3517],      // 2 bug 
    [1, [10.3516, 0, 16.7493]],          // 2 correct     
    [2, [3.19883,9.845,16.7493]],        // 12 
    [3, [-8.37466,6.08454,16.7493]],     // 9        
    [4, [-8.37466,-6.08454,16.7493]],    // 6
    [5, [3.19883,-9.845,16.7493]]        // 1
];

// Not working 
function get_vertex(p) = lookup(p, [0: len(V)-1]);

module lookup_test2()
{
    for (i = [0 : len(V)-1])
    {
        echo(i, get_vertex(i));
    }
}

module search_test()
{
    for (i = [0 : len(V)-1])
    {
        index = search(str(i), V, 1, 0);
        echo(index);
        echo(V[index[0]]);
        echo(V[index[0]][1]);        
        //echo(V[index][0]][1]);
    }    
}

Output

ECHO: [0]
ECHO: 0
ECHO: [0, [0, 0, 19.69]]
ECHO: [0, 0, 19.69]
ECHO: [1]
ECHO: 1
ECHO: [1, [10.3516, 0, 16.7493]]
ECHO: [10.3516, 0, 16.7493]
ECHO: [2]
ECHO: 2
ECHO: [2, [3.19883, 9.845, 16.7493]]
ECHO: [3.19883, 9.845, 16.7493]
ECHO: [3]
ECHO: 3
ECHO: [3, [-8.37466, 6.08454, 16.7493]]
ECHO: [-8.37466, 6.08454, 16.7493]
ECHO: [4]
ECHO: 4
ECHO: [4, [-8.37466, -6.08454, 16.7493]]
ECHO: [-8.37466, -6.08454, 16.7493]
ECHO: [5]
ECHO: 5
ECHO: [5, [3.19883, -9.845, 16.7493]]
ECHO: [3.19883, -9.845, 16.7493]

About janpenguin

Email: janpenguin [at] riseup [dot] net Every content on the blog is made by Free and Open Source Software in GNU/Linux.
This entry was posted in Reprap 3D Printer and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s