HPB (Euler) to Vector ? [SOLVED]

On 13/02/2015 at 09:47, xxxxxxxx wrote:

Hi
I need to convert an HPB value to a vector.  There's loads of stuff on the net about it - but it either didn't work for me or is too confusing :(

Thanks for any help,
Glenn.

On 13/02/2015 at 17:13, xxxxxxxx wrote:

Hi Glenn,

some basic equations about rotations in c4d:  HBP to vector and with Rotation matrix.
You can access all these methods with utils, but it might be better to see what´s going on...

Hope this helps ?
Best wishes
Martin

  
import c4d, math  
  
def main() :  
  print "________________________________________"  
  print "Head = -50°"  
  print "Pitch = 10°"  
  print "Bank = 20°"  
  print "a spline object with two points "  
  print "one at zero vector, the other point moved on e.g. Z-Axis"  
  print "you can rotate the object and check the values given by the script"  
  print "________________________________________"  
    
    
    
  #_________________________  
  #variables  
  matr = op.GetMg()  
  p0 = op.GetPoint(0) * matr  
  p1 = op.GetPoint(1) * matr  
    
  #_________________________  
  #direction vector     
  direction = p0 - p1  
  print direction ,"direction vector"  
  print direction.GetNormalized(), "normalized direction vector"  
    
  #_________________________  
  #direction vector to rotation  
  eu = c4d.utils.VectorToHPB(direction)  
  print eu,"direction to euler rotation in radians"  
  HPB_2 = eu * 180 / math.pi   
  print HPB_2,"HPB_2 in degree with zero banking"   
  #one need at least three points to stabilize a 3d-system   
    
  #_________________________  
  #vector rotation to angle  
  rot = op.GetAbsRot()  
  print rot, "Rotation in radians"  
  HPB = rot * 180 / math.pi  
  print HPB,"Rotation HPB in degree"  
    
  #_________________________  
  #rotation angle to vector   
  rad = HPB * math.pi / 180  
  print rad,"Rotation back to radians"  
    
  
  #_____________________________________________________________  
  #rotation matrices first the single rotations degree to vector  
  #(It would be better to convert to radians first)  
    
    
  ##rotate only H around Y - axis  
  print "________________________________________"  
  print "Single Head rotation"  
  print "Head = -50°, Pitch = 0°, Bank = 0°"  
  print matr.v1  ,"head vector, matrix v1"  
  hhx = math.cos(HPB.x * math.pi / 180)  
  hhy = 0  
  hhz = math.sin(HPB.x * math.pi / 180)  
  print c4d.Vector(hhx, hhy, hhz)  
    
  print matr.v2  ,"pitch vector, matrix v2"  
  hpx = 0  
  hpy = 1  
  hpz = 0  
  print c4d.Vector(hpx, hpy, hpz)  
    
  print matr.v3  ,"bank vector, matrix v3"  
  hbx = -math.sin(HPB.x * math.pi / 180)  
  hby = 0  
  hbz = math.cos(HPB.x * math.pi / 180)  
  print c4d.Vector(hbx, hby, hbz)  
  #R(Y)  
  ymatrix = c4d.Matrix(c4d.Vector(0,0,0),c4d.Vector(hhx, hhy, hhz),c4d.Vector(hpx, hpy, hpz),c4d.Vector(hbx, hby, hbz))  
  
    
  ##rotate only P around X - axis  
  print "________________________________________"  
  print "Single Pitch rotation"  
  print "Head = 0°, Pitch = 10°, Bank = 0°"  
  print matr.v1  ,"head vector, matrix v1"  
  phx = 1  
  phy = 0  
  phz = 0  
  print c4d.Vector(phx, phy, phz)  
    
  print matr.v2  ,"pitch vector, matrix v2"  
  ppx = 0  
  ppy = math.cos(HPB.y * math.pi / 180)  
  ppz = -math.sin(HPB.y * math.pi / 180)  
  print c4d.Vector(ppx, ppy, ppz)  
    
  print matr.v3  ,"bank vector, matrix v3"  
  pbx = 0  
  pby = math.sin(HPB.y * math.pi / 180)  
  pbz = math.cos(HPB.y * math.pi / 180)  
  print c4d.Vector(pbx, pby, pbz)  
  #R(X)  
  xmatrix = c4d.Matrix(c4d.Vector(0,0,0),c4d.Vector(phx, phy, phz),c4d.Vector(ppx, ppy, ppz),c4d.Vector(pbx, pby, pbz))  
    
  ##rotate only B around Z - axis  
  print "________________________________________"  
  print "Single Bank rotation"  
  print "Head = 0°, Pitch = 0°, Bank = 20°"  
  print matr.v1  ,"head vector, matrix v1"  
  bhx = math.cos(HPB.z * math.pi / 180)  
  bhy = -math.sin(HPB.z * math.pi / 180)  
  bhz = 0  
  print c4d.Vector(bhx, bhy, bhz)  
    
  print matr.v2  ,"pitch vector, matrix v2"  
  bpx = math.sin(HPB.z * math.pi / 180)  
  bpy = math.cos(HPB.z * math.pi / 180)  
  bpz = 0  
  print c4d.Vector(bpx, bpy, bpz)  
    
  print matr.v3  ,"bank vector, matrix v3"  
  bbx = 0  
  bby = 0  
  bbz = 1  
  print c4d.Vector(bbx, bby, bbz)  
  #R(Z)  
  zmatrix = c4d.Matrix(c4d.Vector(0,0,0),c4d.Vector(bhx, bhy, bhz),c4d.Vector(bpx, bpy, bpz),c4d.Vector(bbx, bby, bbz))  
    
  #_______________________________________________  
  #rotation matrix all together now   
  #total Rotation is R = R(Y)*R(X)*R(Z)  
  print "________________________________________"  
  print "________________________________________"  
  print "All rotations together"  
  print matr, "c4d Matrix from op.GetMg()"  
  print "multiply all rotation matrices"  
  print ymatrix*xmatrix*zmatrix, "our calculation of a rotation matrix"  
if __name__=='__main__':  
  main()  

On 16/02/2015 at 08:29, xxxxxxxx wrote:

Hello,

you could simply create a Matrix based on your rotation and apply that Matrix to a given Vector as discussed in this thread.

Beset wishes,
Sebastian

On 16/02/2015 at 08:41, xxxxxxxx wrote:

Thanks Sebastian - I already discovered that post, and it solved my problem :)