[draw2d] How to selectively connect an arbitrary number of points



I've just noticed that in

draw2d(  point_type = dot,
             line_width =2,
             color         = blue,
             points_joined = true,
             points([[0,1],[1,2]]),points([[4,4],[5,6]]));

the last line can also be written as a list, that means points() enclosed
in [], terefore

draw2d(  point_type = dot,
             line_width =2,
             color         = blue,
             points_joined = true,
             [points([[0,1],[1,2]]),points([[4,4],[5,6]])]);

At this point it is easy to automatically create a list of couples of
nodes. Well, the problem is solved.

Actually, also the other options inside draw2d() can be enclosed between [
and ], they can be expressed by list, and this is useful.

Stefano





2012/5/22 Stefano Ferri <ferriste at gmail.com>

> I'm sorry, while writing the email I was playing with draw2d and I have
> modifies some values. Of course, if in the draw2d section there is
>
>
> points([[0,1],[1,2]]),points([[4,4],[5,6]]))
>
> it is
>
> NodeCoord : matrix([0,1],[1,2],[4,4],[5,6]);
>
> and also
>
> "The key is how to automatically generate the line
> "points([0,1],[1,2]),points([4,4],[5,6])"...
>
> Stefano
>
>
>
>
> 2012/5/22 Stefano Ferri <ferriste at gmail.com>
>
>> I'm trying to plot some 2-d geometric figures, composed by points
>> selectively joined by lines. I'd like to write a code able to deal with a
>> variable numbers of points and lines (which represent particular
>> connections), but I'm having some difficulties.
>>
>> Points are defined in a matrix with as many rows as the number of points,
>> and two columns (two coordinates for each point). In general, it is an
>> input of my plot script and it has a variable number of rows.
>>
>> Here is an example:
>>
>> NodeCoord : matrix([0,0],[0,1],[2,3],[4,5]);
>>
>> The i-th point corresponds to the i-th line of this matrix.
>>
>> I have another matrix, which defines how points are connected. For
>> example, point 1 is connected to point 2, 3 to 4. I have called this matrix
>> ConnectMatrix.
>>
>> ConnectMatrix : matrix([1,2],[3,4]);
>>
>> Each row of ConnectMatrix defines a line connecting the two points in the
>> row itself.
>>
>> An example of the plot routine is the following:
>>
>> draw2d(  point_type = dot,
>>              line_width =2,
>>              color         = blue,
>>              points_joined = true,
>>              points([[0,1],[1,2]]),points([[4,4],[5,6]]));
>>
>>
>> The key is how to automatically generate the line
>> "points([0,0],[1,0]),points([3,4],[5,6])", considering that the numbers of
>> these elements can be variable. I have to specify a
>> points([[node1],[node2]]) separately for each line, because points can be
>> defined in a sparse order, and only ConnectMatrix establishes how
>> connections are made.
>> I have written a routine capable to generate the
>> points([[node1],[node2]]) for each row of ConnectMatrix, but I'm having
>> troubles with joining them and make draw2d work.
>> For example, I've tried to create a string "points([[node1],node2]]),
>> points([[node1,node2]]" and convert it with flatten, but it remains an
>> atomic expression and draw2d complains about it.
>>
>> Thanks
>> Stefano
>>
>>
>>
>>
>>
>>
>>
>>
>>
>