Tutorial On Creating Own Distance Functions

Discussion in 'ShapeJS' started by xristiaan, Sep 26, 2016.

  1. xristiaan
    xristiaan Member
    I would like to try to write a distance functions myself so that I can create unique shapes.

    Is there any documentation (or better yet a tutorial) on how to do that. And more in general where can I find information on the internal structure of ShapeJS objects so that I can write functions to manipulate them?
     
    pendarestan likes this.
  2. datasurfer
    datasurfer New Member
  3. AlanHudson
    AlanHudson Shapeways Employee Dev Team
    At its easiest its about implementing getBaseValue, ie something like this for a Sphere(abfab3d.datasources.Sphere):

    /**
    * @noRefGuide

    * returns 1 if pnt is inside of ball
    * returns intepolated value if poiunt is within voxel size to the boundary
    * returns 0 if pnt is outside the ball
    *
    * @noRefGuide
    */
    public final int getBaseValue(Vec pnt, Vec data) {

    double v[] = pnt.v;
    double
    x = v[0] - x0,
    y = v[1] - y0,
    z = v[2] - z0;
    double dist = sign*(Math.sqrt(x*x + y*y + z*z)-R);

    data.v[0] = getShapeValue(dist, pnt);

    return ResultCodes.RESULT_OK;

    }

    That said the abfab3d side of the house is not ideal for this as we've been putting most of our energy into the GPU code. It's similar but then the equation must be implemented in OpenCL code.