Arc motion

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 10 October 2013   #1
Arc motion

Hi, I was hoping someone could help me with a small math problem I am having. I cant seem to work out where its going wrong and would appreciate it of someone could lend me a hand. At the moment the radius of the arc seems to be doubled and the movement is in -y as opposed to +y. I would like the sphere to move to the 'end' null's position in an arc motion. Its a simple scene with a small math problem that's got me going so any help would be great.

scene file: Arc_Momevemt.c4d

import c4d
import math

def main():
    obj = op.GetObject()
    frame = doc.GetTime().GetFrame(doc.GetFps())
    freq = op[c4d.ID_USERDATA,1] # The duration it takes to make the move, ie 30 frames
    spline = op[c4d.ID_USERDATA,3] # The pace at which it moves mapped to a spline gui
    end = op[c4d.ID_USERDATA,2] # The end position

    p1 = obj.GetRelPos() #(0,0,0)
    p2 = end.GetRelPos() #(500,0,0)
    center = (p1 + p2)/2
    r = (p1 - p2).GetLength()/2
    p0 = p1 - center
    a0 = math.atan2(p0[1],p0[0])
    a = c4d.utils.RangeMap((frame%freq),0,freq-1,0,math.pi,True,spline)
    newpos = center - c4d.Vector(math.cos(a),math.sin(a),0)*r
    if frame == 0:

Old 10 October 2013   #2

your code is quite confusing, you are mixing global and local coords, you calculate
the angle for your obj in relation the the global coords system a0 and never use it.
Also calculating the rotation matrix in newpos yourself does not seem to be a good
idea as it does not take rotation order into account, resulting in that erratic
movement. Also trying to calculate everything on top of the current position of your
object does make things more complicated than they have to be.

Here is a quick example on how to do a proper rotation. I used a fixed vector bvec
(which would be similar to your center vector). I would use a start pos matrix and
an end pos matrix to calculate bvc dynamically.

import c4d
import math

def main():
    obj = op.GetObject()
    frame = doc.GetTime().GetFrame(doc.GetFps())
    freq = op[c4d.ID_USERDATA,1]
    spline = op[c4d.ID_USERDATA,3]
    end = op[c4d.ID_USERDATA,2]
    bvec = c4d.Vector(250.0, 0.0, 0.0)
    a = c4d.utils.RangeMap(frame % freq, 0.0, freq - 1.0, 0.0, math.pi, False, spline)
    newpos = bvec + c4d.utils.HPBToMatrix(c4d.Vector(0.0, 0.0, a)).MulV(bvec) 
    if frame == 0:
There are holes in the sky. Where the rain gets in.
But they're ever so small. That's why the rain is thin.
Old 10 October 2013   #3
Thank you littledevil, that makes it a lot easier for me to understand where I was going wrong. My home work - to read up a lot more on matrix's.
Old 10 October 2013   #4
You are welcome. Actually matrices aren't too complicated in c4d. On the one hand
you have the matrix class itself and on the other other hand you have the utils module
providing some conversion / construction methods. The three most important are :

// get the rotation vector for a matrix
// construct a rotation vector from a normal
// construct a rotation matrix for a rotation vector (in radians)

The matrix class itself is a 3X4 matrix holding the global offset and x,y,z component.
Aside from the five basic operators for matrices (+,-,*,/,!) there are two important
methods in the matrix class - Matrix.Mul and MulV. Both allow you to apply the matrix
to a vector returning the transformed vector. The first one including translations, the
last one excluding translations.

edit, an example:
There are holes in the sky. Where the rain gets in.
But they're ever so small. That's why the rain is thin.

Last edited by littledevil : 10 October 2013 at 03:40 PM.
Old 10 October 2013   #5
Thanks for the example, that's going to help me out a lot!
Old 11 November 2013   #6
I think I've managed to work out the 2D to 3D problem. Thanks again.

Last edited by hypoly : 11 November 2013 at 08:52 AM.
Old 11 November 2013   #7
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 04:58 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.