[SciPy-User] Triangulate point cloud

Athanasios Anastasiou athanastasiou at gmail.com
Fri Feb 12 09:41:43 EST 2016


Off the top of my head:

from scipy.spatial import distance
from scipy.stats import histogram
from scipy import nan

#p is your data structures that holds all of your data points, it can
be n-dimensional of course.

#Here, it is a list of tuples, suggesting a simple 2D problem.

p=[(2,2),(5,5),(1,7),(2,3)]

#Get the unique distances

#If you have a huge amount of points, this is the point where the
program might take a little bit of time until it comes back with the
results.

d = distance.pdist(p)

#Get the distance matrix, this is always a square kxk matrix, where k
is the index of a point in p

#If you have a huge amount of points, this is the bit where the
program a) takes a long time to finish, b) crashes because of memory
issues. For very large problems, you can upload your points to a
database server and run a query for it to calculate your distance
matrix. So, you can hire a powerful EC2 (for example) instance and run
your query there or run the query over a distributed configuration.
Both options aiming to improve speed and capacity.

Q = distance.squareform(d)

#The d matrix are the unique values of the upper (or lower) diagonal
part of Q. Q is much easier to work with (in terms of referencing), if
you want the distance between any two point m,n you just Q[m,n].

#Here is the Euclidean Q for the above p.

#array([[ 0.        ,  4.24264069,  5.09901951,  1.        ],
#       [ 4.24264069,  0.        ,  4.47213595,  3.60555128],
#       [ 5.09901951,  4.47213595,  0.        ,  4.12310563],
#       [ 1.        ,  3.60555128,  4.12310563,  0.        ]])


#Get the histogram of that

H = histogram(d); #This could also be done on Q, by reshaping it to a
1 x (M*N) vector but if you have a huge number of points it is not
advisable. You can see how quickly this eats up memory.

#This can also be done with matplotlib.pyplot.hist(d) which will also
draw the histogram for you besides returning it.

If you want to free up some memory to fit even more data to your
problem, you can round everything to a few decimal places and use
integers. So, for example, int(round(5.678928527817364 *
10000))==56789, which is a nice little unsigned integer of 2 bytes
instead of a double of 8 bytes. Of course this assumes that 4 decimals
is accurate enough. To get back to your data range, just divide by
10000 and assign to (float or double).


Hope this helps.


All the best

AA





On Fri, Feb 12, 2016 at 1:24 PM, Vasco Gervasi <yellowhat46 at gmail.com>
wrote:

> Thanks. I will try mayavi and blender.
> Regarding the suggestione number 1 of AA do you have an example.
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> https://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20160212/509a811c/attachment.html>


More information about the SciPy-User mailing list