2
$\begingroup$

I'm building a visualisation where I have a body that is moving along-a-path, which is comprised of multiple segments, each with an arbitrary angle.

The body is moving along the path and:

  • When the body's centre reaches the end of each segment it stops.
  • It then rotates around it's centre to align itself with the next segment .
  • It starts moving again along the next segment.

I can get this working just fine when the rotation point is the body's centre.

Here's an animation of the body rotating by it's centre (blue dot):

gif showing the body moving along a path, rotating by its centre

However now I'd like to rotate the body from a pivot point.

How can I calculate the distance I should cover in each segment before I stop and start turning around my pivot, so when the rotation ends my body's centre lies exactly in the centre of the next segment?

In short, when the body is moving it's centre must always lie on the segment line it moves on.

Here's an animation of the body rotating by it's pivot point (red dots):

gif showing the body moving along the path, rotating by it's pivot

In the above example the body overshoots the position on each segment where it should stop and start rotating, thus when it starts moving again - it's centre doesn't lie on the path.

FWIW I've got some code for this working in a browser sandbox, available here

$\endgroup$
2
$\begingroup$

If your body's centre must always be on a segment while moving in straight line, your problem looks impossible to me when the rotation pivot is "in front" of the body centre. If you allow the centre to only lie on the (infinite) line through the (finite) segment, consider the situation below.

Geometric configuration at the adequate pivot location

To preserve the front of the body at the front, you should rotate by the same angle $\theta$ between the two line segments. Let $O'$ be the rotation of $O$ around the pivot, the locus of $O'$ as $O$ moves along the first line, is a line parallel to that first line. Intersect that locus with the second line, and you'll obtain the location of $O'$ after the appropriate rotation, from which you can deduce the position of the pivot, and the position of the body centre $O$.

$\endgroup$
4
  • $\begingroup$ @NicholasKyriakides I just wanted to make sure, so I prefaced my answer with that. But basically the rest of my answer is about where to stop on the infinite line $A$ so that the centre of your body ends up on the infinite line $B$ after rotating around your pivot. Depending on the specific position of your pivot wrt your centre, it's not always possible to keep your centre on the (finite) segments with only a rotation around the pivot. $\endgroup$
    – N.Bach
    Jan 24 '18 at 1:54
  • $\begingroup$ Ok - That's great, thanks! $\endgroup$ Jan 24 '18 at 2:13
  • $\begingroup$ So basically this means that I should: a) Find the next segments theta angle - b) Place a point on the centre of the body - c) Rotate that point around my pivot by 'theta' angle - d) start moving - e) stop when that point intersects the infinite line of the next segment. Am I getting this correctly? $\endgroup$ Jan 24 '18 at 14:49
  • $\begingroup$ @NicholasKyriakides Yes, that is one (among many) possible implementation of the strategy I presented. The "best" implementation would depend on what exactly you are trying to do with your visualisation, and what your body is supposed to model. Though if it is purely for visualisation purposes, you can "cheat" a little and pre-process your path in advance, if you find it simpler to handle pre-processed paths. $\endgroup$
    – N.Bach
    Jan 24 '18 at 16:59
1
$\begingroup$

You should turn when pivot point $N$ reaches the angle bisector of $\angle ABC$, with a rotation of $2\angle BNO$. But the rotated body is turned by $180°-2\angle BON$ with respect to the direction of the path.

enter image description here

To make this work, then, you must choose your pivot so that $\angle BON=90°$.

enter image description here

$\endgroup$
3
  • $\begingroup$ I edited my answer because I realized that your idea is feasible with a particular choice of the pivot. $\endgroup$ Jan 24 '18 at 7:45
  • $\begingroup$ But wait - I can't arbitrarily choose my pivot positions. They are at a fixed position w.r.t the body's centre $\endgroup$ Jan 24 '18 at 14:57
  • 1
    $\begingroup$ In that case you must follow the approach suggested by N.Bach. $\endgroup$ Jan 24 '18 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.