BTW here is our code for calculating barycoordinates from points and
creating points from barycoordinates:

template<class T>
class Triangle3 {
public:
        Vec3<T> a;
        Vec3<T> b;
        Vec3<T> c;

        Matrix44<T> getPointToBarycoordMatrix() const;
        Matrix44<T> getBarycoordToPointMatrix() const;
};

template<class T>
inline Matrix44<T> Triangle3<T>::getPointToBarycoordMatrix() const {
        M44x pointToBarycoordMatrix;
        bool success = inverseSafe( pointToBarycoordMatrix,
getBarycoordToPointMatrix() );
        if( ! success ) {
                T oneThird = ((T)1.0)/((T)3.0);
                //Vec3<T> center = ( a + b + c ) * oneThird;
                return Matrix44<T>(
                        0, 0, 0, 0,
                        0, 0, 0, 0,
                        0, 0, 0, 0,
                        oneThird, oneThird, oneThird, 0);
        }
        return pointToBarycoordMatrix;
}

template<class T>
inline Matrix44<T> Triangle3<T>::getBarycoordToPointMatrix() const {
        Vec3<T> n = normal();
        return Matrix44<T>(
                a[0], a[1], a[2], 1,
                b[0], b[1], b[2], 1,
                c[0], c[1], c[2], 1,
                n[0], n[1], n[2], 0);
}

And this you just multiple your point by the "pointToBarycoordMatrix"
matrix to get barycoords.  And if you have barycoordinates, multiply
it by "getBarycoordToPointMatrix()" to get your point.

We are using 4 coordinate barycoordinates where the fourth element is
the distance from the triangle plane in the normal direction.  Just
set it to zero and you should be fine.  The above can be converted to
Softimage Matrix types pretty easily.  Probably could be added to the
Softimage SDK as well if it isn't already there.

Best regards,
-ben


On Wed, Jul 17, 2013 at 12:04 PM, Ben Houston <b...@exocortex.com> wrote:
> So barycoords for a triangle works well and I believe there are tons
> of references on the web for this.  Barycoordinates for polygons is a
> bit more problematic because they are no longer linear but rather
> polynomials and thus harder to calculate.  I'd stick with triangles
> and then all those web references should work well.
>
> Is your problem calculating them from points?
>
> Basically this is a great guide:
>
> http://en.wikipedia.org/wiki/Barycentric_coordinate_system
>
> -ben
>
>
> On Wed, Jul 17, 2013 at 11:38 AM,  <p...@bustykelp.com> wrote:
>> Hi, I have spent days on this and I cant work it out
>>
>> I have a selection of points (not on a flat plane) and I have a test
>> position.
>> It returns an array that represents the weighting, related to the proximity
>> to the other points.
>>
>> I want to have it so that when the test position is directly at a point, the
>> value for that point in the array = 1
>> and the rest will be zero
>> as the test point moves around the area it interpolates these values, but
>> they always add up to 1
>>
>> It sounds really easy, but I’ve been literally* tearing my hair out over
>> this for days.
>>
>> Ive managed to get barycentric interpolation working for a flat plane, and
>> only 3 points, but I need it to accept multiple points in 3d space.
>>
>> Please help. I’m going bonkers over this
>>
>> Paul
>>
>> *(not really literally)
>
>
>
> --
> Best regards,
> Ben Houston
> Voice: 613-762-4113 Skype: ben.exocortex Twitter: @exocortexcom
> http://Exocortex.com - Passionate CG Software Professionals.



-- 
Best regards,
Ben Houston
Voice: 613-762-4113 Skype: ben.exocortex Twitter: @exocortexcom
http://Exocortex.com - Passionate CG Software Professionals.

Reply via email to