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
#6
(Jan-18-2021, 08:39 AM)paul18fr Wrote: You can easily check using the example of the website I gave you.

My advices: use vectorization instead of a loop, and above all, do not use append (dynamic memory allocation is time consuming); have a look to the code here bellow as an example.

Of course by replacing and increasing the n value, the area tends to 1

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as mtri
 
 
axes=plt.axes()
n = 10_000
# x=np.random.random(n)
# y=np.random.random(n)
x= np.array( [ 15, 23, 50] ) # see https://www.mathopenref.com/coordtrianglearea.html 
y= np.array( [ 15, 30, 25] ) # Area = 222.5 for these 3 vertices

axes.set_xlim([0,1])
axes.set_ylim([0,1])
 
# plt.scatter(x,y)
# plt.show()
 
plt.scatter(x,y)
plt.show()
 
# Delanuay Triangulation method
triang = mtri.Triangulation(x, y)
plt.triplot(triang, 'ro:')

VNN = triang.triangles
# print(VNN)
a,b=VNN.shape

i = np.arange(a)
# formula: Area = 0.5*| (Xb-Xa)(Yc-Ya)-(Xc-Xa)(Yb-Ya) | where a,b,c are 3 vertices
Area = np.sum( np.abs (0.5*( (x[VNN[i,1]]-x[VNN[i,0]])*(y[VNN[i,2]]-y[VNN[i,0]]) - \
                             (x[VNN[i,2]]-x[VNN[i,0]])*(y[VNN[i,1]]-y[VNN[i,0]]) )))

print("Area = {}".format(Area))

I do not understand the reason for saying "Of course by replacing and increasing the n value, the area tends to 1" and so for having n = 10_000. Could you elaborate more?

Thanks,
Valerio
Reply


Messages In This Thread
RE: Surface area of triangles generated by Triangulation - by meValerio - Apr-05-2022, 10:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  new in this area Ana_junior 2 83,347 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