ConvexHull
ConvexHull is a class in spatial. Its main function is to find the edges of a set of points and make a convex hull. The necessary initialization parameter is a point set, the point set format is an array of n×m dimensions, n is the number of points in the point set, and m is the dimension of the point.
from scipy.spatial import ConvexHull import matplotlib.pyplot as plt import numpy as np pts = np.random.rand(30, 2) hull = ConvexHull(pts) plt.plot(pts[:,0], pts[:,1], 'o') for i in hull.simplices: plt.plot(pts[i, 0], pts[i, 1], 'k-') plt.show()
simplex
is the serial number of the index point. The effect after drawing is as follows
ConvexHull has two optional parameters, among which, incremental is a Boolean parameter. When it is True, new points are allowed to be added.
The specific parameters of qhull_options can be viewed in qhull. Only QG will be demonstrated below.
QG
QGn means treating the nth point as an observation point. After dividing the point set by convex hull, if the vertices are connected and used as a wall, then the observation point can The points that can be seen are marked as good, and the effect is as follows
pts = np.random.rand(1000, 2) # 添加一个观察点 pts = np.vstack([pts, np.array([[2,0.5]])]) hull = ConvexHull(pts, qhull_options='QG1000') plt.plot(pts[:,0], pts[:,1], '.') for i in hull.simplices: plt.plot(pts[i, 0], pts[i, 1], 'k-') for i in hull.simplices[hull.good]: plt.plot(pts[i, 0],pts[i, 1], lw=5) plt.show()
The effect is as shown in the figure
Three-dimensional situation
The convex hull in two dimensions is obviously a closed figure composed of lines, while the convex hull in three dimensions should naturally be a three-dimensional geometry. Expanded to any dimension, the convex hull is actually a simplex. The simplices in ConvexHull are the points that form the simplex and are indexed in the origin set. An example is as follows
pts = np.random.rand(30, 3) hull = ConvexHull(pts) ax = plt.subplot(projection='3d') ax.scatter(pts[:,0], pts[:,1], pts[:,2]) for i in hull.simplices: ax.plot_trisurf(pts[i, 0], pts[i, 1], pts[i,2], alpha=0.5) plt.show()
The alpha parameter is used to adjust the transparency of the triangular surface, so that the points inside the convex hull can be seen through the convex hull.
The effect is as follows
ConvexHull attribute
The concept of a simplex has been introduced before, that is, the figure composed of the convex hull is a simplex . As a two-dimensional case, the convex hull is surrounded by line segments; in the three-dimensional case, the convex hull is surrounded by planes; extended to any dimension, it can be expressed as a simplex that constitutes the convex hull, surrounded by hypersurfaces. Since the concept of hypersurface has no boundaries, the convex hull surface with vertices and edges is referred to as a simplex hypersurface in the following.
The commonly used attributes in the ConvexHull class are as follows
points Point set surrounded by convex hull
vertices Simplex vertices at points Concentrated indexes
simplices Simplex metasurface vertices
neighbors Indexes of hypersurface adjacent hypersurfaces
equations Parameters of hypersurface equations
Examples of hypersurface equations in three dimensions are as follows, that is, each hypersurface has 4 parameters
>>> hull.equations array([[-0.5509472 , 0.72386104, -0.41530999, -0.36369123], [-0.26155355, 0.16210178, -0.95147925, 0.02022163], [-0.99132368, -0.0460725 , 0.12310441, 0.045523 ], [-0.98526526, -0.07170442, 0.15527666, 0.04749854], [-0.15900968, -0.98529789, -0.06248198, 0.13294496], # .......
The above is the detailed content of How to plot convex hull in Python?. For more information, please follow other related articles on the PHP Chinese website!

InPython,youappendelementstoalistusingtheappend()method.1)Useappend()forsingleelements:my_list.append(4).2)Useextend()or =formultipleelements:my_list.extend(another_list)ormy_list =[4,5,6].3)Useinsert()forspecificpositions:my_list.insert(1,5).Beaware

The methods to debug the shebang problem include: 1. Check the shebang line to make sure it is the first line of the script and there are no prefixed spaces; 2. Verify whether the interpreter path is correct; 3. Call the interpreter directly to run the script to isolate the shebang problem; 4. Use strace or trusts to track the system calls; 5. Check the impact of environment variables on shebang.

Pythonlistscanbemanipulatedusingseveralmethodstoremoveelements:1)Theremove()methodremovesthefirstoccurrenceofaspecifiedvalue.2)Thepop()methodremovesandreturnsanelementatagivenindex.3)Thedelstatementcanremoveanitemorslicebyindex.4)Listcomprehensionscr

Pythonlistscanstoreanydatatype,includingintegers,strings,floats,booleans,otherlists,anddictionaries.Thisversatilityallowsformixed-typelists,whichcanbemanagedeffectivelyusingtypechecks,typehints,andspecializedlibrarieslikenumpyforperformance.Documenti

Pythonlistssupportnumerousoperations:1)Addingelementswithappend(),extend(),andinsert().2)Removingitemsusingremove(),pop(),andclear().3)Accessingandmodifyingwithindexingandslicing.4)Searchingandsortingwithindex(),sort(),andreverse().5)Advancedoperatio

Create multi-dimensional arrays with NumPy can be achieved through the following steps: 1) Use the numpy.array() function to create an array, such as np.array([[1,2,3],[4,5,6]]) to create a 2D array; 2) Use np.zeros(), np.ones(), np.random.random() and other functions to create an array filled with specific values; 3) Understand the shape and size properties of the array to ensure that the length of the sub-array is consistent and avoid errors; 4) Use the np.reshape() function to change the shape of the array; 5) Pay attention to memory usage to ensure that the code is clear and efficient.

BroadcastinginNumPyisamethodtoperformoperationsonarraysofdifferentshapesbyautomaticallyaligningthem.Itsimplifiescode,enhancesreadability,andboostsperformance.Here'showitworks:1)Smallerarraysarepaddedwithonestomatchdimensions.2)Compatibledimensionsare

ForPythondatastorage,chooselistsforflexibilitywithmixeddatatypes,array.arrayformemory-efficienthomogeneousnumericaldata,andNumPyarraysforadvancednumericalcomputing.Listsareversatilebutlessefficientforlargenumericaldatasets;array.arrayoffersamiddlegro


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
