Dear Scripters I need your help, please.

I become crazy… since a couple of day´s (or better week´s) I try to get this work.

on 4:20 on this video you see some arrows:

The arrows are linked with the rotor of the induction motor.

The Length of the arrows depend´s on the magnetic N and S field.

Every time N or S hit the arrow it should became 150% on N and -150% on S

Between the pole´s I need the scale value 0

My animation is a simple out of range animation controlled by an ease curve.

At first glance, it seemed easy to write an expression for it, even as a beginner.

But as an neeby in scripting I struggle with the syntax und much more with formula´s.

My first stumbling block was that the value of X_Rotation is in Rad, so it take some time to find out, I have to multiplicate with 57,295779513 to get Grad.

But now I use

MyPfeil = getNodeByName “Pfeil007”

MyDummy = getNodeByName “Dummy001”

X_Rotation = coordsys gimbal MyDummy.rotation.x

RotAngle = atan2 (coordsys world MyPfeil.pos.Z - MyDummy.Pos.Z) (MyPfeil.Pos.Y - MyDummy.Pos.Y)

to get the Grad Value and to find out the angle between my Dummy and the Arrow(´s).

Because of the “out of range” rotation I get very high rotation angles, which i clean up by integer:

DrehA = int (X_Rotation/360)

DrehB = X_Rotation - (DrehA*360)

As you can see in the video from 4:20 the arrows length depend on the angle of the magnetic field (N/S) but the rotation is linked at the rotor.

I made two scripts to play around, but often I get unexpected results.

Most I find out, so like RotAngle was 90° ((150/90)*RotAngle)/100 where I expect 1.5

and get 0.9, because of an integer data type…

Typical beginner error I guess

Whenever I’m close to it and think “now I’ve got it” it slips back into the distance

Please help me to keep mental health:grin:

Thank you in Advance!

Josef

Script1

MyPfeil = getNodeByName “Pfeil006” --Scale object

MyDummy = getNodeByName “Dummy001”

MyRotorDummy = getNodeByName “Dummy002” --Rotation of the rotor

X_Rotation = coordsys gimbal MyRotorDummy.rotation.x

DrehA = int (X_Rotation/360)

DrehB = X_Rotation - (DrehA*360)

RotAngle = atan2 (coordsys world MyPfeil.pos.Z - MyDummy.Pos.Z) (MyPfeil.Pos.Y - MyDummy.Pos.Y)-- get vector

Dreh = RotAngle --+ DrehB

if (Dreh == 0 or Dreh == 180 or Dreh == -180) then ScaleA = 0 else

if (Dreh == 45) or (Dreh == 135) then ScaleA = 0.75 else

if (Dreh == -45) or (Dreh == -135) then ScaleA = -0.75 else

if (Dreh == 90) then ScaleA = 1.5 else

if (Dreh == -90) then ScaleA = -1.5

print ScaleA

Script2

MyPfeil = getNodeByName “Pfeil006” --Scale object

MyDummy = getNodeByName “Dummy001” --Rotate dummy to get vectors (probably not necessary)

MyRotorDummy = getNodeByName “Dummy002” --Rotation of the rotor

X_Rotation = coordsys gimbal MyDummy.rotation.x

DrehA = int (X_Rotation/360) --the integer cut decimal

DrehB = X_Rotation - (DrehA*360) --cleaned angle, because of the out of range

RotAngle = atan2 (coordsys world MyPfeil.pos.Z - MyDummy.Pos.Z) (MyPfeil.Pos.Y - MyDummy.Pos.Y) --get vector

Dreh = RotAngle + DrehB --not used in this first step

if (RotAngle > 0) and (RotAngle <= 90) then ScaleA = ((150.0/90.0)*RotAngle)/100.0 else
if (RotAngle > 90) and (RotAngle <= 180) then ScaleA = (150.0/90.0)*(RotAngle-90.0)/100.0 else

if (RotAngle <= 0) and (RotAngle >= -90) then ScaleA = ((150.0/90.0)

*RotAngle)/100.0 else*

if (RotAngle < -90) and (RotAngle > -179.9) then ScaleA = (150.0/90.0)(RotAngle+90.0)/100.0

if (RotAngle < -90) and (RotAngle > -179.9) then ScaleA = (150.0/90.0)

Test file

test02.max (944 KB)