@@ -463,34 +463,63 @@ def rotate(self, deg_angle=None, rad_angle=None, axis='x'):
463463 elif id == 3 :
464464 self .root_face = face
465465
466- def mirror (self , point1 , point2 , point3 ):
466+ def mirror (self , * args , ** kwargs ):
467467 """
468- 3D mirroring of the blade with respect to a plane defined by three points
469-
470- :param list point1: coordinates of point1
471- :param list point2: coordinates of point2
472- :param list point3: coordinates of point3
468+ 3D mirroring of the blade with respect to a plane.
469+ The plane can be defined either by three points or by a point and its normal direction.
470+ Which option to be used depends on the inputs taken by the funtion.
473471
472+ args: -three entries means three points
473+ -two entries means one point and one normal vector
474+ kwargs: -only accepted arguments: point1, point2, point3, normal
474475 """
475476 if len (self .blade_coordinates_up ) == 0 :
476477 raise ValueError ('You must apply transformations before rotation.' )
477478
479+ if len (args ) + len (kwargs ) not in [2 , 3 ]:
480+ raise ValueError ("Wrong number of arguments" )
481+
482+ admissible_kwargs = ['point1' , 'point2' , 'point3' , 'point' , 'normal' ]
483+ if any (key not in admissible_kwargs for key in kwargs .keys ()):
484+ raise ValueError ('Wrong argument. Admissible arguments are only {}' .format (admissible_kwargs ))
485+
478486 from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_Transform
479487 from OCC .Core .gp import gp_Pnt
480488 from OCC .Core .gp import gp_Vec
481489 from OCC .Core .gp import gp_Dir
482490 from OCC .Core .gp import gp_Ax2
483491 from OCC .Core .gp import gp_Trsf
484492
485- point1 = gp_Pnt (* point1 )
486- point2 = gp_Pnt (* point2 )
487- point3 = gp_Pnt (* point3 )
493+ if len (args ) == 3 :
494+ # Case where the three points are passed
495+ point1 = gp_Pnt (* args [0 ])
496+ point2 = gp_Pnt (* args [1 ])
497+ point3 = gp_Pnt (* args [2 ])
498+ # Two vectors defining the directions of the plane
499+ vector1 = gp_Vec (point1 , point2 )
500+ vector2 = gp_Vec (point2 , point3 )
501+ # Normal versor to the plane passing through the three points
502+ normal = gp_Dir (vector1 .Crossed (vector2 ))
503+ elif list (kwargs .keys ()) == ['point1' , 'point2' , 'point3' ]:
504+ # Case where the three points are passed
505+ point1 = gp_Pnt (* kwargs ['point1' ])
506+ point2 = gp_Pnt (* kwargs ['point2' ])
507+ point3 = gp_Pnt (* kwargs ['point3' ])
508+ # Two vectors defining the directions of the plane
509+ vector1 = gp_Vec (point1 , point2 )
510+ vector2 = gp_Vec (point2 , point3 )
511+ # Normal versor to the plane passing through the three points
512+ normal = gp_Dir (vector1 .Crossed (vector2 ))
513+ elif len (args ) == 2 :
514+ # Case where one point and the normal are passed
515+ point1 = gp_Pnt (* args [0 ])
516+ normal = gp_Dir (* args [1 ])
517+ elif sorted (kwargs .keys ()) == sorted (['point' , 'normal' ]):
518+ point1 = gp_Pnt (* kwargs ['point' ])
519+ normal = gp_Dir (* kwargs ['normal' ])
520+ else :
521+ raise ValueError ('Wrong arguments passed' )
488522
489- # Two vectors defining the directions of the plane
490- vector1 = gp_Vec (point1 , point2 )
491- vector2 = gp_Vec (point2 , point3 )
492- # Normal versor to the plane passing through the three points
493- normal = gp_Dir (vector1 .Crossed (vector2 ))
494523 # Ax2 object identifying the plane
495524 ax2 = gp_Ax2 (point1 , normal )
496525
0 commit comments