Changeset 5899:38a3bb3c0def


Ignore:
Timestamp:
08/24/07 00:03:27 (6 years ago)
Author:
Robert Bradshaw <robertwb@…>
Branch:
default
Children:
5900:d169f23c4cb4, 5936:bd86b75bcd21
Message:

Line command, for making cylinders from P to Q

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/plot/graphics3d.py

    r5898 r5899  
    1515""" 
    1616from random import randint 
     17from math import atan2 
    1718 
    1819from sage.structure.sage_object import SageObject 
     
    269270            # rotate about v by theta 
    270271            vx, vy, vz, theta = rot 
    271             if vz != 0: 
    272                 t = atan(vy/vz) + pi/2 
    273                 m = self.rotX(t) * m 
    274                 new_y = vy*cos(t) - vz*sin(t) 
    275             else: 
    276                 t = 0 
    277                 new_y = vy 
     272            t = atan2(vy,vz) + pi/2 
     273            m = self.rotX(t) * m 
     274            new_y = vy*cos(t) - vz*sin(t) 
    278275            # v = [vx, new_y, 0] 
    279             if new_y != 0: 
    280                 s = atan(vx/new_y) + pi/2 
    281                 m = self.rotZ(s) * m 
    282             else: 
    283                 s = 0 
     276            s = atan2(vx,new_y) + pi/2 
     277            m = self.rotZ(s) * m 
    284278            # v = [new_x, 0, 0] 
    285279            m = self.rotX(theta) * m 
     
    483477    Create a cylindar from start to end with radius radius. 
    484478    """ 
    485     start = vector(RDF, start) 
    486     end = vector(RDF, end) 
    487     yaxis = vector(RDF, (0,1,0)) 
     479    start = vector(RDF, start, sparse=False) 
     480    end = vector(RDF, end, sparse=False) 
     481    zaxis = vector(RDF, (0,0,1), sparse=False) 
    488482    diff = end - start 
    489483    height = sqrt(diff.dot_product(diff)) 
    490484    cyl = Cylinder(radius, height, **kwds) 
    491     axis = yaxis.cross_product(diff) 
    492     theta = -acos(yaxis.dot_product(diff)/height) 
    493     return cyl.rotate(axis, theta).translate(start) 
    494  
     485    axis = zaxis.cross_product(diff) 
     486    if axis == 0: 
     487        return cyl 
     488    else: 
     489        theta = -acos(diff[2]/height) 
     490        return cyl.rotate(axis, theta).translate(start) 
    495491 
    496492class Sphere(PrimativeObject): 
Note: See TracChangeset for help on using the changeset viewer.