Re: [Algorithms] How to get 3dvector largest coordinate index?
Brought to you by:
vexxed72
From: Olivier G. <gal...@po...> - 2009-02-27 16:47:50
|
On Fri, Feb 27, 2009 at 11:02:58AM -0500, Matt J wrote: > Hmm, I fail to see how this works: > > If (y > x) == 0 then that means x <= y. > > So, > > If x <= y and z < y then 0 << 0 = 0 > If x <= y and z >= y then 0 << 1 = 0 > > In the first case, y is the greatest component In the second case, z is the > greatest component. > > Both are encoded as 0. Something I'm missing? The max. That formula has more fabs than sense. A quick rewrite would be: x = abs(v.x); y = abs(v.y); z = abs(v.z) return (x < max(y,z)) << (z >= y) which is obviously correct. OG. > > > Hi, > > > > I need to compute the index (not the actual value) of the largest > > coordinate of a normal, for some space hashing. > > > > I'm not sure how fast you guys usually find this index, but I've just > > created the following trick which I think is quite fast: > > > > > inline uint LargestCoordinate(const Vector3d &v) > > > { > > > const float x = fabs(v.x); > > > const float z = fabs(v.z); > > > const float y = Maths::max( fabs(v.y), z ); > > > return uint(fabs(y)>fabs(x)) << uint(fabs(z)>=fabs(y)); > > > } > > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list |