Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

June 04, 2013

two ways to min/max an xyz coordinate list

coords = [
(-4.76519775390625, -2.480715036392212, -1.0),
(-4.76519775390625, -2.480715036392212, 2.3569369316101074),
(-4.76519775390625, 1.0000009536743164, 2.3569369316101074),
(-4.76519775390625, 1.0000009536743164, -1.0),
(2.8928911685943604, -2.480715036392212, -1.0),
(2.8928911685943604, -2.480715036392212, 2.3569369316101074),
(2.8928911685943604, 1.0000009536743164, 2.3569369316101074),
(2.8928911685943604, 1.0000009536743164, -1.0)
]
def p(num): print("method", num)
p(1)
# rotate first
rotated = zip(*coords[::-1])
for (axis, _list) in zip('xyz', rotated):
print(axis, 'min', min(_list), 'max', max(_list))
p(2)
# not rotated
def extreme(func, i): return func(coords, key=lambda k: k[i])[i]
for i in range(3):
print('xyz'[i], 'min', extreme(min, i), 'max', extreme(max, i))
view raw coordinates.py hosted with ❤ by GitHub