1

Is there anything better than what I have now? The solving on the angle's constraint is getting tedious.

This was originally AS3: http://www.lorenzonuvoletta.com/wp-content/uploads/others/Main.as

The angle of freedom are constrained by an in and out angle degree HTML sliders.

I'm only sampling the one point by entering:

if (i - 1 == 0) {
   angle = solve(points[i - 1], points[i], 'right lock');
}

in the loop.

But when I get to solving the joint angle's freedom is gets jumpy when I bring it to the left: enter image description here

  function solve(point, delta, LF) {
      if (!delta.out || !delta.in) return point.s;

      point.s = point.s > Math.radians(delta.in.value) + delta.s
        ? Math.radians(delta.in.value) + delta.s
        : point.s < delta.s - Math.radians(delta.out.value)
            ? delta.s - Math.radians(delta.out.value)
            : point.s;

      console.log(point.s);
      console.log(delta.s);
      console.log('Out: ' + (delta.s - Math.radians(delta.out.value)));
      console.log('In: ' + (Math.radians(delta.in.value) + delta.s));

      return point.s;// return slope
  }

Code:

function computeLeftPoints() {
  var points = _points[_ikIndex];
  var distance = points[0].distance;
  var lock = points[0].lock;
  var angle;
  //var i;
  var iMod = 0;
  if (!lock) iMod = 1;

  for (let i = _pActive; i > 1 - iMod; i--) {
    points[i - 1].s = angle = Math.slope(points[i - 1], points[i]);

    points[i - 1].a = Math.angle(points[i - 2], points[i - 1], points[i]);
    points[i - 1].ap = anglePoint(points[i - 1]);

    if (i - 1 == 0) {
      angle = solve(points[i - 1], points[i], 'left');
    }
    points[i - 1].x = points[i].x + distance * Math.cos(angle); //Must be rounded unless will cause error in arc
    points[i - 1].y = points[i].y + distance * Math.sin(angle);
  }
  if (lock) {
    for (let i = 0; i < _pActive; i++) {
      points[i + 1].s = angle = Math.slope(points[i + 1], points[i]);

      points[i + 1].a = Math.angle(points[i + 2], points[i + 1], points[i]);
      points[i + 1].ap = anglePoint(points[i + 1]);

      if (i + 1 == 0) {
        angle = solve(points[i + 1], points[i], 'left lock');
      }
      points[i + 1].x = points[i].x + distance * Math.cos(angle);
      points[i + 1].y = points[i].y + distance * Math.sin(angle);
    }
  }
}

function computeRightPoints() {
  var points = _points[_ikIndex];
  var distance = points[0].distance;
  var lock = points[0].lock;
  var angle;
  var i;
  var iMod = 0;
  if (!lock) iMod = 1;

  for (i = _pActive; i < points.length - 2 + iMod; i++) {
    points[i + 1].s = angle = Math.slope(points[i + 1], points[i]);

    points[i + 1].a = Math.angle(points[i + 2], points[i + 1], points[i]);
    points[i + 1].ap = anglePoint(points[i + 1]);

    if (i + 1 == 0) {
      angle = solve(points[i + 1], points[i], 'right');
    }

    points[i + 1].x = points[i].x + distance * Math.cos(angle);
    points[i + 1].y = points[i].y + distance * Math.sin(angle);
  }
  if (lock) {
    for (i = points.length - 1; i > _pActive; i--) {
      points[i - 1].s = angle = Math.slope(points[i - 1], points[i]);

      points[i - 1].a = Math.angle(points[i - 2], points[i - 1], points[i]);
      points[i - 1].ap = anglePoint(points[i - 1]);

      if (i - 1 == 0) {
        angle = solve(points[i - 1], points[i], 'right lock');
      }

      points[i - 1].x = points[i].x + distance * Math.cos(angle); //Must be rounded unless will cause error in arc
      points[i - 1].y = points[i].y + distance * Math.sin(angle);
    }
  }
}

function solve(point, delta, LF) {
  if (!delta.out || !delta.in) return point.s;

  point.s = point.s > Math.radians(delta.in.value) + delta.s
    ? Math.radians(delta.in.value) + delta.s
    : point.s < delta.s - Math.radians(delta.out.value)
        ? delta.s - Math.radians(delta.out.value)
        : point.s;

  console.log(point.s);
  console.log(delta.s);
  console.log('Out: ' + (delta.s - Math.radians(delta.out.value)));
  console.log('In: ' + (Math.radians(delta.in.value) + delta.s));

  return point.s;// return slope
}

Where I just sample the neck it works fine on the right side but on the left, I guess, I should of finished constrains up on day one... haha, I had the idea of it before.

Leroy Thompson
  • 470
  • 3
  • 13
  • didn't read all your code, but telling by the clip, you might want to extend the joints. Not only providing a degree of freedom, but also a default/normal angle. And now think of these joints as if they were spring loaded. try to minimize the sum of `difference(currentAngle, defaultAngle)` for the whole strain. If you also add a value for each joint how string this spring is, it should look pretty natural. – Thomas Mar 21 '17 at 23:47
  • normal angle, just incase I may need to offset to reset the angle solving, I'll try this – Leroy Thompson Mar 21 '17 at 23:56

0 Answers0