# Bezier angles on IPO window

Hello all,
I’m still trying to screipt a wizard to cconvert a bezier spline to IPO graphs, and while I have locations working, the rotation part isn’t, and its just bonkers, that and realizing some weeks ago that I need to divide my angle by 10 to commply with silly Euler notation.
Anyway, I realize that I need to do an arc tangent, and have that working based on two vectors, doing basic trig, my current problem is that when playing back the animation it doesn’t rotate as it follows the path, and I am really lost as to what I can do, any ideas?

Ps Please don’t post complex math notation equations, I can’t read them:spin:

``````def Plot_Rot(myCurrentPathLen, myBezPointNumber, myPathIter):
print "function."
SideA = H2_X - P_X
SideB = H2_Y - P_Y
print "Side A: %s    Side B: %s" % (SideA, SideB)
AngleC = atan2 (SideA, SideB)
print "Arc tan: %s" % AngleC
SideD = H1_X - P_X
SideE = H1_Y - P_Y
print "Side D: %s    Side E: %s" % (SideD, SideE)
AngleF = atan2 (SideD, SideE)
print "Arc tan: %s" % AngleF
AngleG = (AngleC + AngleF) / 2
#AngleF = 180 +AngleF
#AngleC = (90 * myBezPointNumber)

#Angle = Blender.Mathutils.AngleBetweenVecs (SideA, SideB)
#print"BezNumber: %s" % myBezPointNumber
#print"AngleC: %s" % AngleC
# make 3 BezTriples, and mke sure their handles are FREE
# pass eacch of these 3 new BezTriples for X, Y and Z
# to their relevant IPO's
#myIPOCurvePitch = Blender.BezTriple.New(myCurrentPathLen - myHandleIter, Angle, 0, myCurrentPathLen, Angle, 0, myCurrentPathLen + myHandleIter, Angle, 0)
#myIPOCurveRoll = Blender.BezTriple.New(myCurrentPathLen - myHandleIter, Angle, 0, myCurrentPathLen, Angle, 0, myCurrentPathLen + myHandleIter, Angle, 0)
myIPOCurveYaw = Blender.BezTriple.New(myCurrentPathLen - myHandleIter, AngleF / 10, 0, myCurrentPathLen, AngleG / 10, 0, myCurrentPathLen + myHandleIter, AngleC / 10, 0)

#myIPOCurvePitch.handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
#myIPOCurveRoll.handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)
myIPOCurveYaw.handleTypes = (Blender.BezTriple.HandleTypes.FREE, Blender.BezTriple.HandleTypes.FREE)

#myIPOCurveRot_X.append(myIPOCurvePitch)
#myIPOCurveRot_Y.append(myIPOCurveRoll)
myIPOCurveRot_Z.append(myIPOCurveYaw)

print "function."

myCurrentPathLen = myPathIter * myBezPointNumber
#myIPOCurveRot_Z.append((myCurrentPathLen, Angle2 / 10))
``````

Can no one help?

bumping

I have got as far as checking which quadrant the second vector is in relation to the first, and use Pythagorean theorem to get the distance between the two vectors, but now i’m stuck, I don’t know how to create an expression that tells the script to follow and angle that turns obtuse, or how to relate it to the the last set of vectors
Handle 1 and Knot 1
Knot1 to Knot 2
Handle 2 to Knot 2
relates to the last set of these, are they necessary, will it stay smooth if left out

I can’t actually code this until these questions and more are answered.

Edit, oh I forgot to mention that I am working on Bezier splines so the general data is the same, just in 3D, and at this stage excluding Pitch and Roll vectors, or my head will explode

okay, I tried (5 minutes) to get the script working
I believe it needs some From Blender import … import blender … import math , etc
but I’m too lazy atm to add any of that (and could be doing my homework atm as well)

eg: it does something, right? Well, don’t make it hard to figure out (upload a .blend please )

Hmm, ok, I didn’t think that one out through enough, I can definitely upload a blend file, but its likely to confuse and confound, thats why I just pasted the module i’m working on only

Just one mo and i’ll upload it

Here is the blend file
to execute the script, make sure you’re in object mode and select the curve, in this case the scenario is a circle
right click in the text editor and execute script
select the Empty
and select the IPO curve in the IPO curve editor window
scripting.blend

Edit: Both the function above and what is my script is wrong on a couple of levels

1. There is no taking into account 90, 180 and 270 degree angles
2. Using an Arc tangent function is a flawed plan because it fails on 90 and 270 degrees

Hence I stopped coding it until i have a far better plan of how to tackle this big problem

I can definitely upload a blend file, but its likely to confuse and confound, thats why I just pasted the module i’m working on only

okay, I tried (5 minutes) to get the script working
I believe it needs some From Blender import … import blender … import math , etc
but I’m too lazy atm to add any of that (and could be doing my homework atm as well)
there’s a reason I’m lazy this needs some serious “# what the heck does this do?” comments

and yes, I’m clueless on the coding

Edit: Both the function above and what is my script is wrong on a couple of levels

1. There is no taking into account 90, 180 and 270 degree angles
2. Using an Arc tangent function is a flawed plan because it fails on 90 and 270 degrees
I know you’ve probably already thought this one out… but (just wondering) have you tried arcsin / arccos yet? (those are just about never undefined )

I also noticed you’re using trig… would vector math be easier in this situation?
you can use vectors in 3d space, and define the direction in all routes which would solve your pitch problem.

: also you’ve already started somewhat and you’re getting numbers from these vectors and converting to numbers and then back to vectors… why not just keep it in the vectors?

Ps Please don’t post complex math notation equations, I can’t read them:spin:
… hmmm… maybe if I tried explaining it ? ? (if not http://en.wikipedia.org/wiki/Dot_product#Geometric_interpretation )
also, this stuff is probably already coded into the API stuff here: http://www.blender.org/documentation/242PythonDoc/Mathutils.Vector-class.html

[edit: I spent some time writing this out, so… it stays ]
( " * "is the a dot for the dot product of 2 vectors, a = <a.1, a.2>, b = <b.1 ,b.2> )
then you could say that cos(theta)= |a * b| /(|a||b|)

(defining stuff in above statement)
|a * b| = (a.1)(b.1) + (a.2)(b.2) (the dot product - basically vector components each multiplied together, then added) The result is a positive whole number , if 0 , then 2 vectors are perpendicular

|a| = sqrt( (a.1)^2 +(a.2)^2) (the magnitude of a)
|b| = sqrt( (b.1)^2 +(b.2)^2) (the magnitude - overall length - of b )
(and of course, a 3d vector would be exactly the same process , only with a and b having a 3rd component - eg: a = <a.1, a.2, a.3>
this would output a number and would probably be easier to work with

dunno, if you’re still like " wtf ? " maybe try #math on freenode for those math related coding questions?

Yeah, vector math is just little beyond me at this stage, having not done that at school (a long story), but will be attending when I can get around to it some math papers at university.

But i’m willing to slog through it and try to understand it, hence why I asked not to post the complex math notations, i have a better chance understanding it if it just straight complex algebra, which you did - Thanks.

I am at this stage deciding whether to use Arc Sine or Arc Cosine, as I can implement that easily enough with pythag.

But i’m still not totally convinced that that equation will work beyond 90 degrees and still keep going.

Did you do alt+a on the 3d window, cause that should give an idea of what I am trying to achieve
At knot 0 rotation is at 0
At knot 1 rotation is at 90
At knot 2 rotation is at 180 not 0
At knot 3 rotation is at 270
At knot 4 rotation is at 360 not 0

Is there a way to do it that takes into account vector director based on the last set of vectors?
Cause I had just about given up hope of finding such an equation.

I take it that freenode is a math junkie forum is it, might have look there as well

I have to thank you again, i’m researching this Angle between vectors thing, found a neat set of tutorials that explain it well.
http://programmedlessons.org/VectorLessons/index.html

Just a thought, Grogyan…

Have you tried the atan2(a,b) function rather than the atan(a,b) function? It takes into account the sign of the variables a and b in order to give the resulting angle in the range [-pi, pi] rather than only giving a single possible angle based on the absolute lengths of the two sides of the triangle (without considering their signs and therefore their orientation to each other).

Not sure if this is what you need, but I think Python implements this C function as part of it’s specification. It should be in the “math” module, I think… If it’s there.

This should resolve the issue that you’re having with the symmetry of trig functions though. Maybe you’re losing the signs of your vectors somewhere so the atan2() function isn’t doing it’s job right?

Actually the ArcTan function works the way its meant to, problem was that I hadn’t taken to account the knots, it was just the handles.

Then I had started thinking about it, and there is a problem when using the Arc Tan, a serious bug would occur at 90 and 270 degrees due to the nature of tangents.

Then i’ve started looking around for solutions and AMDBCG suggested looking at the AngleBetweenVecs function, but I don’t know how to get that to work, and i’d have to do normailese() before then. The neat thing about the angle between vecs is that it does take into account perpendicular vectors.

Then I was thinking more about that, yeah I do a lot of that, I can do boolean expressions all the way up to 180 degrees, after that it becomes stuck, and thats where i’m up to.

Man this script is seriously getting complicted, math wise.

Not sure what to do whether to leave it and mod the Path2Ipo script, or what?

Maybe the bugs that occur at 90 and 270 degrees are a result of the tangent of the angle tending to infinity at that point. Have you tried checking for a 90 or 270 degree angle and resetting them to an angle that is close (such as 89.999999 degrees)? I’ve read that this is a popular workaround when dealing with code that has the potential to deal with the concept of infinity. I’m not sure exactly how you’re managing the angles, but this workaround may work if it’s relevant.

eg.

``````
if angle == 90:
angle = 89.999999
elif angle == 270:
angle = 269.99999

``````

well I think the best approach still is to use the AngleBetweenVecs (), as opposed to standard trig, because I reckon that i’ll be needing the last vector coordinate to give the correct angle value

to get over the problem of the 270 degree glitch, and the only viable way to do that is to use math, ie the AnglebetweenVecs() and normalise(), and add that value that is +/_ to the last rotation, and utilizing the handle offset should at least in my head, will help to differentiate angles above 180