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 10467 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 an array like:
, , , ]
should look after sorting like
, , , ]
|
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 coordinates.
The algorithm that I am trying to implement says that the resulting data structure is a multi-pointer list ((d-1)tuply threaded list), each node of which is threaded in each of the single pointer lists corresponding to the chosen...
|
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 coords and put all the objects
in the same coordinate together.
|
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 x-coordinate. I am trying to use the "sort" function defined in algorithms.h and I am getting a segmentation fault. I have inlined the code below. Can someone please tell me what I am doing wrong ? I am compiling this code on linux ( fedora 6 x86_64 using...
|
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 generate random
coordinate points (x,y) and compare them with user inputted coordinate
points. For example how will I be able to access the separate values,
the x from the x,y position. I think I understand everything except
1)the random coordinate...
| |
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) using the Point as the key
I could always use try and true method of a binary search algorithm
but I rather not.
|
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
vector. Given a target coordinate (x,y)_t, I would like to be able to
cycle through the vector of points in order to obtain the closest
point. What would be the most efficient way to implement this?
I have considered keeping the vector sorted...
|
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 angle between the two points, see the
image in the link for what I mean.
http://homepage.ntlworld.com/andrew.baldock/bloodbowl/select.png
I am not interested in displaying anything in the rectangle, I just need
|
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |