Python Forum
Surface area of triangles generated by Triangulation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Surface area of triangles generated by Triangulation
#3
Thank you so much for your kind help.

I tried the following code. it seems to work for huge number of points.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as mtri

np.random.seed(0)
axes=plt.axes()
x=np.random.random(10000)
y=np.random.random(10000)
axes.set_xlim([0,1])
axes.set_ylim([0,1])

plt.scatter(x,y)
plt.show()

# # Delanuay Triangulation method
triang = mtri.Triangulation(x, y)
#plt.triplot(triang, 'ro:')

AZ=triang.neighbors
print(AZ)

# VerticesNodesNumbers = VNN
VNN = triang.triangles
print(VNN)
a,b=VNN.shape
print(a)
#print("x\n{}\n".format(x))
#print("y\n{}\n".format(y))

Arealiste=[]
# in order to calculate the area of each single triangle, we need to scann
# the VNN 2D Array by the number of raws only. 

for i in range(a):
    t1=(x[VNN[i][0]])*((y[VNN[i][1]])-(y[VNN[i][2]]))
    t2=(x[VNN[i][1]])*((y[VNN[i][2]])-(y[VNN[i][0]]))
    t3=(x[VNN[i][2]])*((y[VNN[i][0]])-(y[VNN[i][1]]))
    Arealiste.append(abs((t1+t2+t3)/2))

#print(Arealiste)

Areas=np.array(Arealiste)
#print(Areas)
print(np.sum(Areas))
k=(Areas/(np.sum(Areas)))*100
#print(k)
# we can now plot the histogram of the area distribution of the triangles:-)
plt.hist(k,1000)
plt.show()
Could you please check?
I appreciate your support for any further hints :-)
Reply


Messages In This Thread
RE: Surface area of triangles generated by Triangulation - by pythonformaterialsci - Jan-16-2021, 07:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  new in this area Ana_junior 2 83,360 Jan-05-2021, 08:58 AM
Last Post: Ana_junior

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020