object moves, always looking to direction of movement?!

Mar 25, 2011 at 12:24pm

object moves, always looking to direction of movement?!

Hi

I have an object moving along a curved path. [jit.gl.sketch]
Now i want that object always looking in the direction of movement.

I use:
[cartopol] –> [expr ($f1 / 3.1415926) * 180.] –> (shapeorient $1 $2 0.) –> [jit.gl.sketch]

Only X and Y change Z axis stays 0.

I can’t get it working properly.
What am i missing here?

– Pasted Max Patch, click to expand. –
#55809
Mar 30, 2011 at 6:24pm

Nobody can help me out, point me to the good direction to look?

#200655
Mar 31, 2011 at 3:59pm

Hey, so the problem you are trying to solve is to find direction between two points in 3D space (or in your case 2D space) as a (signed?) angle (is this the correct term? Angle of slope? Whatever…).

So basically you need atan2 (which is atan(q)x/y).

Pardon the rough patching… I spent way more time on this than I have free right now…

– Pasted Max Patch, click to expand. –
#200656
Mar 31, 2011 at 4:01pm

Sorry I didn’t explain correctly, the issue is that first you need to find the slope angle from the last known point to the current point, not just from 0,0 (which I *think* is what cartpol is potentially doing in your patch().

#200657
Mar 31, 2011 at 5:20pm

For this kind of thing, I have had excellent results using the Cosm objects.

http://www.allosphere.ucsb.edu/cosm/

#200658
Apr 2, 2011 at 9:23am

@cap10subtext: Thanks, it works now very well. I had already tried with [atan2] but had forgotten to inject the position A again to turn the object. Stupid me.
@Andrew Benson: I have checked the Cosm objects and sure i can do it with these objects, but i first want to find a solution with the original Max objects. Thanks.

#200659
Apr 3, 2011 at 4:07pm

Cosm = da bomb and Graham (and everyone else who’s worked on them) has done AMAZING work with the example patches to help with this. But the principle is the same. I’ve always been rusty on the math so now, to understand what the patches are doing in Cosm I find I have to build it and work out the math myself once or twice so i can understand what’s going on.

In this case, even I’d forgotten that you had to determine from the new position at first. So, not stupid. Now we both know!

#200660

You must be logged in to reply to this topic.