@@ -404,6 +404,7 @@ def rotate(self, deg_angle=None, rad_angle=None, axis='x'):
404404 elif deg_angle is not None :
405405 cosine = np .cos (np .radians (deg_angle ))
406406 sine = np .sin (np .radians (deg_angle ))
407+ rad_angle = deg_angle * np .pi / 180
407408 else :
408409 raise ValueError (
409410 'You have to pass either the angle in radians or in degrees.' )
@@ -429,6 +430,39 @@ def rotate(self, deg_angle=None, rad_angle=None, axis='x'):
429430 self .blade_coordinates_down = np .einsum ('ij, kjl->kil' ,
430431 rot_matrix , self .blade_coordinates_down )
431432
433+ # TODO: working but ugly
434+ for id , face in enumerate ([self .upper_face , self .lower_face ,
435+ self .tip_face , self .root_face ]):
436+ from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_Transform
437+ from OCC .Core .gp import gp_Pnt
438+ from OCC .Core .gp import gp_Dir
439+ from OCC .Core .gp import gp_Ax1
440+ from OCC .Core .gp import gp_Trsf
441+
442+ origin = gp_Pnt (0 , 0 , 0 )
443+ if axis == 'y' :
444+ direction = gp_Dir (0 , 1 , 0 )
445+ elif axis == 'z' :
446+ direction = gp_Dir (0 , 0 , 1 )
447+ elif axis == 'x' :
448+ direction = gp_Dir (1 , 0 , 0 )
449+ else :
450+ raise ValueError ('Axis must be either x, y, or z.' )
451+ ax1 = gp_Ax1 (origin , direction )
452+ trsf = gp_Trsf ()
453+ trsf .SetRotation (ax1 , rad_angle )
454+
455+ brep_tr = BRepBuilderAPI_Transform (face , trsf , True , True )
456+ face = brep_tr .Shape ()
457+ if id == 0 :
458+ self .upper_face = face
459+ elif id == 1 :
460+ self .lower_face = face
461+ elif id == 2 :
462+ self .tip_face = face
463+ elif id == 3 :
464+ self .root_face = face
465+
432466 def scale (self , factor ):
433467 """
434468 Scale the blade coordinates by a specified factor.
@@ -438,11 +472,29 @@ def scale(self, factor):
438472 from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_Transform
439473 self .blade_coordinates_up *= factor
440474 self .blade_coordinates_down *= factor
441- # for face in [self.upper_face, self.lower_face, self.tip_face, self.root_face]:
442- # brepgp_Trsf = BRepBuilderAPI_Transform()
443- # brepgp_Trsf.SetScale(gp_Pnt(0, 0, 0), factor)
444- # brepgp_Trsf.Perform(face, True)
445- # face = brepgp_Trsf.Shape()
475+
476+ for id , face in enumerate ([self .upper_face , self .lower_face ,
477+ self .tip_face , self .root_face ]):
478+ from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_Transform
479+ from OCC .Core .gp import gp_Pnt
480+ from OCC .Core .gp import gp_Dir
481+ from OCC .Core .gp import gp_Ax1
482+ from OCC .Core .gp import gp_Trsf
483+
484+ origin = gp_Pnt (0 , 0 , 0 )
485+ trsf = gp_Trsf ()
486+ trsf .SetScale (origin , factor )
487+
488+ brep_tr = BRepBuilderAPI_Transform (face , trsf , True , True )
489+ face = brep_tr .Shape ()
490+ if id == 0 :
491+ self .upper_face = face
492+ elif id == 1 :
493+ self .lower_face = face
494+ elif id == 2 :
495+ self .tip_face = face
496+ elif id == 3 :
497+ self .root_face = face
446498
447499 def plot (self , elev = None , azim = None , ax = None , outfile = None ):
448500 """
@@ -944,3 +996,15 @@ def __str__(self):
944996 string += '\n Induced rake from skew (in unit length)' \
945997 ' for the sections = {}' .format (self .induced_rake )
946998 return string
999+
1000+ def display (self ):
1001+ """
1002+ Display the propeller with shaft.
1003+ """
1004+ from OCC .Display .SimpleGui import init_display
1005+ display , start_display = init_display ()[:2 ]
1006+ display .DisplayShape (self .upper_face , update = True )
1007+ display .DisplayShape (self .lower_face , update = True )
1008+ display .DisplayShape (self .root_face , update = True )
1009+ display .DisplayShape (self .tip_face , update = True )
1010+ start_display ()
0 commit comments