Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

I am trying to use a driver with a scripted expression to place an object's rotation in between the rotation of two other angle-measuring objects.

So there are objects I've labeled BeginAngle and EndAngle, as well as ResultAngle. I've managed to script it so that ResultAngle will be placed exactly halfway in the middle using:

((endangle-beginangle)/2)

What I really want to do is not just place it halfway but instead specify ratios in decimal like 0.333, 0.618 etc. My Python and math skills have proven insufficient thus far.

enter image description here

.blend file here.

Thanks for any help!

Things to note: Rotation along Blender's Z axis is inverted (- degrees), making this trickier. Also you may need to tick "Auto-Run Python Scripts" under Preferences > File.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

I assume you mean that you want a "convex combination" of the angles, so that:

  • 0 will return an angle that is just BeginAngle
  • 0.5 will return an angle halfway between BeginAngle and EndAngle
  • 0.33 will return an angle that is closer to BeginAngle than EndAngle

In that case, you can use the scripted expression:

(1.0 - 0.33) * BeginAngle + (0.33) * EndAngle
share|improve this answer
    
Fantastic! Elegantly simple and customizable. Exactly the sort of answer I was hoping for. Just tried it out. Thank you. –  Mentalist Mar 29 at 10:01

Linear interpolation, AKA Mix, good idea! If there are weird results then be sure to check that you know how to convert between radians and degrees. This is one of those situations where this conversion is often necessary. radians = degrees x Pi / 180.0

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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