Hi ,
I have a list of points and I have to find the boundary nodes from the points.
For example :
pointList = [ [1.2,1.2,10],[10.5,1.3,9.5],[5,0.6,9.8],[1.1,5.0,9.2],[10.1,5.3,8.0]]
How to sort the coordinate values in the list based on X:Xmin,Xmax
Y:Ymin,Ymax,Z: Zmin and Zmax?.Is there any method or function available in Python to sort the list values based on the X ,Y and Z values
Thanks in Advance
PSB
1 10444 bvdet 2,851
Recognized Expert Moderator Specialist
Hi ,
I have a list of points and I have to find the boundary nodes from the points.
For example :
pointList = [ [1.2,1.2,10],[10.5,1.3,9.5],[5,0.6,9.8],[1.1,5.0,9.2],[10.1,5.3,8.0]]
How to sort the coordinate values in the list based on X:Xmin,Xmax
Y:Ymin,Ymax,Z: Zmin and Zmax?.Is there any method or function available in Python to sort the list values based on the X ,Y and Z values
Thanks in Advance
PSB
The list method sort() will order the list on the first element. If any two first elements are the same, then it looks at the second element. I wrote this function to sort point lists on a given attribute - x, y, or z: - def sortPoints(_ptlist, key='x'):
-
try:
-
if key.lower() in ['x', 'y', 'z']:
-
def cmpItems(a,b):
-
return cmp(eval('a.'+key.lower()), eval('b.'+key.lower()))
-
_ptlist.sort(cmpItems)
-
else:
-
raise AttributeError, 'Invalid attribute was passed to sortPoints()'
-
except:
-
raise TypeError, 'Invalid point list'
-
-
ptList = [Point(1.0,2.0,3.0), Point(0.5,1.0,7.0), Point(12.6,-12.9,-15.6), Point(-99, 12.6, 1700),\
-
Point(29.6, 44.4, 19.1), Point(22.8, 12.2, 4.54)]
-
-
print formatPtList_("Unsorted points list:", ptList)
-
-
sKey = "Y"
-
sortPoints(ptList, sKey)
-
-
print formatPtList_("Points list sorted on '%s' attribute:" % (sKey), ptList)
-
-
"""
-
Unsorted points list:
-
X attribute Y attribute Z attribute
-
============================================================
-
1 2 3
-
1/2 1 7
-
1'-0 5/8 -1'-0 7/8 -1'-3 5/8
-
-8'-3 1'-0 5/8 141'-8
-
2'-5 5/8 3'-8 3/8 1'-7 1/8
-
1'-10 13/16 1'-0 3/16 4 9/16
-
-
Points list sorted on 'Y' attribute:
-
X attribute Y attribute Z attribute
-
============================================================
-
1'-0 5/8 -1'-0 7/8 -1'-3 5/8
-
1/2 1 7
-
1 2 3
-
1'-10 13/16 1'-0 3/16 4 9/16
-
-8'-3 1'-0 5/8 141'-8
-
2'-5 5/8 3'-8 3/8 1'-7 1/8
-
"""
You also could get the max and min values for x, y and z: - >>> pointList = [[1.2, 5.0, 9.1999999999999993], [1.2, 5.0, 10], [5, 0.59999999999999998, 9.8000000000000007], [10.1, 5.2999999999999998, 8.0], [10.5, 1.3, 9.5]]
-
>>> xList = [p[0] for p in pointList]
-
>>> yList = [p[1] for p in pointList]
-
>>> zList = [p[2] for p in pointList]
-
>>> map(max, [xList, yList, zList])
-
[10.5, 5.2999999999999998, 10]
-
>>> map(min, [xList, yList, zList])
-
[1.2, 0.59999999999999998, 8.0]
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Maarten van Reeuwijk |
last post by:
I'm a newbie to Python, so sorry for this maybe trivial question. I have a
numpy array with coordinates, which I want to sort, for example first on
z-coordinate, then x and lastly y-coordinate. So...
|
by: acosgaya |
last post by:
Hi, I would like some help as how to approach the following problem:
I have a set of d-dimensional points (e.g (3,5,8,9,5) is a 5-dimensional point), and I need to sort the points on each of the...
|
by: JoeC |
last post by:
I am completly lost.
I would like to create a function that takes two vectors.
These two vectors have objects with x and y coords, what I want to do
find all the objects in the same x and y...
|
by: jwlkr |
last post by:
Hi,
I am trying to sort a vector of a user defined type: a class which represents points in cartesian coordinates. The vector of points needs to be sorted according to the value of the...
|
by: Eric.Gabrielson |
last post by:
Hello,
I am very knew to python and am attempting to write a program
in python that a friend of mine is having to write in java. I am doing
this for fun and would like some help as to how i can...
| |
by: shortyes |
last post by:
Is there any easy way to sort a list of Points by either its X or Y or
both?
Tried
sortedlist (of String, Point) where string is Point.X & "," & Point.Y
as the key
sortedlist (of Point, Point)...
|
by: kimt |
last post by:
Hello, I am currently writing an application that involves many (>
1000) points on a (x,y) plane. I am using a struct to contain the
position information, and I have the structs contained in a STL...
|
by: John |
last post by:
Hi there,
I need to create a rectangle between two points so that I can check what
is inside it using Contains(). The problem I am having is how to make the
rectangle be able to cope with the...
|
by: TommyC |
last post by:
Hi all,
Kindly need your attention here.
Let say,
n = 0; // number of corner points detected
if (......)
{
corner_list.x = j; //x coordinate
corner_list.y = i; //y coordinate
n++;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |