Rotate have some problems with python

traiduong014969
Collaborator

Rotate have some problems with python

traiduong014969
Collaborator
Collaborator

Dear all, 

I want to rotate rod for handrail . This code that sound is correct, however when I test block. This resolves is not as expected. Actually, I wanna the rod (this yellow color ) to create OY direction with k angle as snapshot below. when I test code both of them is duplicated and create OY with 0 degrees.  I don't know this code has the problem but when I replace k =30, etc... with a number, (not parameter assignment). this resolve is correct again , not duplicate rod (this yellow color). Someone can explain for me ?. I tried many ways, but that is duplicate and create with OY with O degree

 

Thank you in advance!

traiduong014969_2-1637859060208.png

 

traiduong014969_0-1637858208469.png

traiduong014969_1-1637858582806.png

 

 

 

 

0 Likes
Reply
Accepted solutions (1)
455 Views
2 Replies
Replies (2)

nghiabt04
Advocate
Advocate
Accepted solution

@traiduong014969 ,

you are using integer parameter, k turn to be k = 0 from the calculation (integer parameter will round your result).

It's mean:

C/D = 0.5 but in integer its will round to 0 -> sin(0) = 0, so k = 0.

Solution is using float parameter. Code here:

 

import aqa.math
import math
from varmain.primitiv import *
from varmain.var_basic import *
from varmain.custom import *

@activate(Group="Support", TooltipShort="Support", TooltipLong="Support", LengthUnit="mm")
@group("MainDimensions")
@group(Name="meaningless enum")
@enum(1, "align X")
@enum(2, "align Y")
@enum(3, "align Z")

def HANDRAIL(s, D = 1200.0, D1=25.0, H=1000.0, H1=30.0 ,Alpha=25.0, Beta=30.0, A=30.0, B=100.0, C=600.0,  ID = 'HANDRAIL', **kw):
    """
    D = 1200 is integer
    D = 1200.0 is float
    """


    o1a=CYLINDER(s, R=D/2-D1/2, H=B, O= D/2-D1/2-5).translate((0, 0 ,H1))

    o2a = TORUS(s, R1=D/2, R2=D1/2).translate((0, 0,H))
    o2b = TORUS(s, R1=D/2, R2=D1/2).translate((0, 0,H/2))

    
    k= math.degrees(math.asin(C/D))

    print k

    o2c=CYLINDER(s, R=D1/2, H=H, O= 0).translate((0, -D/2 ,0)).rotateZ(-k)

    o2c1=CYLINDER(s, R=D1/2, H=H, O= 0).translate((0, -D/2 ,0)).rotateZ(k)

    o2c.setColor(2)
    o2c1.setColor(2)



    N=6
    if N>1:

        phi=225/(N-1)
        FirstAngle = phi/2

    No=0
    
    InAngle = FirstAngle
    while(No<N):

        o3a=CYLINDER(s, R=D1/2, H=H, O= 0).translate((0, -D/2 ,0)).rotateZ(InAngle+45.5)


        InAngle= InAngle+ phi
        No= No+1
    # (TESTACPSCRIPT "HANDRAIL")
    

 I tried and got success. 

traiduong014969
Collaborator
Collaborator
Thank you so much, it works perfectly
0 Likes