
! script name: vpkscrews.d/wallangle
! topic: calculates the wall angle from the Y offset

!A
!A NAME:
!A
!A	Calculate Wall Angle
!A
!A DESCRIPTION:
!A
!A
!B INSTRUCTIONS:
!B
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: screw wall angle")

DIM Destination$[256]
DIM Answer$[256]
DIM Title$[256]
DIM A$[256]
DIM File$[256]

DEG

File$= "tempdata"

Start:!
Cutter_dia:!
Stat=SetInputFormat("n6")
Cutter_dia=GetValue("CUTTER DIAMETER",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Cutter_angle:!
Stat=SetInputFormat("n6")
Cutter_angle=GetValue("CUTTER TAPER ANGLE",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Screw_pitch:!
Stat=SetInputFormat("n6")
Pitch=GetValue("PITCH",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Od_diameter:!
Stat=SetInputFormat("n6")
Od_diameter=GetValue("OD DIAMETER",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Root_diameter:!
Stat=SetInputFormat("n6")
Root_diameter=GetValue("ROOT DIAMETER",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Y_offset:!
Stat=SetInputFormat("n6")
Y_offset=GetValue("Y OFFSET",Answer$)
IF (ExitScript(Destination$)) THEN Leave

R1= 0.5*Root_diameter
R2= 0.5*Od_diameter

Lead_edge=CreateGroup("TEMPGROUP")
Trail_edge=CreateGroup("TEMPGROUP")
FOR I= 0 TO 10

R2= R1+(I/10)*(0.5*Od_diameter-R1)

Root_Helix_angle= ATN(Pitch/(2*PI*R1))
Od_Helix_angle= ATN(Pitch/(2*PI*R2))
Crad= 0.5*Cutter_dia+ (R2-R1)*TAN(Cutter_angle)

X1= Crad*COS(Root_helix_angle)-(Y_offset-Crad*SIN(Root_helix_angle))*TAN(Root_helix_angle)

X2= Crad*COS(Od_helix_angle)-(Y_offset-Crad*SIN(Od_helix_angle))*TAN(Od_helix_angle)

! Wall_angle= ATN((X2-X1)/(R2-R1))

Stat=SetCurrentColor(3)
Pt= PointXYZ(-X2,R2,0)
Stat=AddToGroup(Lead_edge,Pt)
! BACKSIDE

Root_Helix_angle= ATN(Pitch/(2*PI*R1))+180
Od_Helix_angle= ATN(Pitch/(2*PI*R2))+180
X1= Crad*COS(Root_helix_angle)-(Y_offset-Crad*SIN(Root_helix_angle))*TAN(Root_helix_angle)

Stat=SetCurrentColor(4)
X2= Crad*COS(Od_helix_angle)-(Y_offset-Crad*SIN(Od_helix_angle))*TAN(Od_helix_angle)
Pt= PointXYZ(-X2,R2,0)
Stat=AddToGroup(Trail_edge,Pt)


NEXT I

S1=CSCurvePtGrp(Lead_edge,Pt,0,Pt,0)
S2=CSCurvePtGrp(Trail_edge,Pt,0,Pt,0)
P1= ParameterPt(S1,0.0)
P2= ParameterPt(S2,0.0)
L1= LineTwoPoints(P2,P1)
Stat=DeleteEntityList(P1,P2)
P1= ParameterPt(S1,1.0)
P2= ParameterPt(S2,1.0)
L2= LineTwoPoints(P1,P2)
Stat=DeleteEntityList(P1,P2)
Stat=DeleteGroup(Lead_edge)
Stat=DeleteGroup(Lead_edge)
Stat=DeleteGroup(Trail_edge)
G1=CreateGroup("CutterTrackProfile")
Stat=AppendToGroup(G1,S1)
Stat=AppendToGroup(G1,L2)
Stat=AppendToGroup(G1,S2)
Stat=AppendToGroup(G1,L1)

Cont_group= JoinEntities(G1)
Num_contours= GroupCount(Cont_group)
Stat=DeleteEntity(G1)
IF Num_contours THEN
        Color1= CurrentColor
        Stat= SetSelectedFlag(Cont_group,WsTrue)
        Stat=PlotEntity(Cont_group)
        FOR I=1 TO Num_contours
                Contour= GroupElement(Cont_group,I)
                Stat=AutoNumberCont(Contour)
                IF Color1 THEN
                        Stat=SetColor(Contour,Color1)
                        Stat= SetSelectedFlag(Contour,WsFalse)
                        Stat=PlotEntity(Contour)
                END IF
        NEXT I
        Stat= SetSelectedFlag(Cont_group,WsFalse)
END IF
Stat=DeleteEntity(Cont_group)

GOTO Screw_pitch


Leave:!
Stat=SetInputFormat("n4","")
LowerSelectBox
IF (NOT LEN(Destination$)) THEN
	  LOAD "typecontrol"
ELSE
	  LOAD Destination$
END IF
END
