@@ -454,6 +454,9 @@ def clear_lines(self):
454454 self .lines = dict ()
455455
456456
457+ # TODO: Split plot into simplot(), which adds points to existing lines,
458+ # and plot(), which does not
459+
457460def plot (* args , ** kwargs ):
458461 """Makes line plots.
459462
@@ -889,32 +892,32 @@ def polar(self):
889892
890893 def hat (self ):
891894 """Returns the unit vector in the direction of self."""
892- """
893- """
894895 return self / self .mag
895896
897+ def perp (self ):
898+ """Returns a perpendicular Vector (rotated left).
899+
900+ Only works with 2-D Vectors.
901+
902+ returns: Vector
903+ """
904+ assert len (self ) == 2
905+ return Vector (- self .y , self .x )
906+
896907 def dot (self , other ):
897908 """Returns the dot product of self and other."""
898- """
899- """
900909 return np .dot (self , other ) * self .units * other .units
901910
902911 def cross (self , other ):
903912 """Returns the cross product of self and other."""
904- """
905- """
906913 return np .cross (self , other ) * self .units * other .units
907914
908915 def proj (self , other ):
909916 """Returns the projection of self onto other."""
910- """
911- """
912917 return np .dot (self , other ) * other .hat ()
913918
914919 def comp (self , other ):
915920 """Returns the magnitude of the projection of self onto other."""
916- """
917- """
918921 return np .dot (self , other .hat ()) * other .units
919922
920923 def dist (self , other ):
@@ -958,7 +961,28 @@ def Vector(*args, units=None):
958961 return _Vector (args , found_units )
959962
960963
964+ def plot_segment (A , B , ** options ):
965+ """Plots a line segment between two Vectors.
966+
967+ Additional options are passed along to plot().
968+
969+ A: Vector
970+ B: Vector
971+ """
972+ xs = A .x , B .x
973+ ys = A .y , B .y
974+ plot (xs , ys , ** options )
975+
976+
961977def cart2pol (x , y , z = None ):
978+ """Convert Cartesian coordinates to polar.
979+
980+ x: number or sequence
981+ y: number or sequence
982+ z: number or sequence (optional)
983+
984+ returns: theta, rho OR theta, rho, z
985+ """
962986 x = np .asarray (x )
963987 y = np .asarray (y )
964988
@@ -972,6 +996,14 @@ def cart2pol(x, y, z=None):
972996
973997
974998def pol2cart (theta , rho , z = None ):
999+ """Convert polar coordinates to Cartesian.
1000+
1001+ theta: number or sequence
1002+ rho: number or sequence
1003+ z: number or sequence (optional)
1004+
1005+ returns: x, y OR x, y, z
1006+ """
9751007 if hasattr (theta , 'units' ):
9761008 if theta .units == UNITS .degree :
9771009 theta = theta .to (UNITS .radian )
0 commit comments