You might find this useful for testing:
!NoteWorthyComposer(2.75)
|PgSetup|StaffSize:18|Zoom:6
|AddStaff|Name:"Staff"
|StaffProperties|EndingBar:Open (hidden)|WithNextStaff:Layer
|User|BeamRestChords.fso|Pos:-2|DurNote2:Sixteenth|Color:1
|RestChord|Dur:32nd|Opts:Stem=Up,StemLength=7,HideRest|Dur2:4th|Pos2:1
|Rest|Dur:16th,Dotted|Visibility:Never
|RestChord|Dur:32nd|Opts:Stem=Up,StemLength=6,HideRest|Dur2:4th|Pos2:-2
|Rest|Dur:32nd|Visibility:Never
|User|BeamRestChords.fso|Pos:-2|DurNote2:Sixteenth|Color:1
|RestChord|Dur:32nd|Opts:Stem=Down,StemLength=6,HideRest|Dur2:4th|Pos2:1
|Rest|Dur:16th,Dotted|Visibility:Never
|RestChord|Dur:32nd|Opts:Stem=Down,StemLength=7,HideRest|Dur2:4th|Pos2:-2
|Rest|Dur:32nd|Visibility:Never
|Bar|Style:Double
|Note|Dur:8th|Pos:1|Opts:Stem=Down,StemLength=7,Beam=First
|Note|Dur:16th|Pos:-2|Opts:Stem=Down,StemLength=6,Beam=End
|Note|Dur:8th|Pos:1|Opts:Stem=Up,StemLength=6,Beam=First
|Note|Dur:16th|Pos:-2|Opts:Stem=Up,StemLength=7,Beam=End
|Bar|Style:Double
|AddStaff|Name:"Staff-2"
|StaffProperties|EndingBar:Open (hidden)
|Note|Dur:8th|Pos:1|Opts:Stem=Down,StemLength=7,Beam=First
|Note|Dur:16th|Pos:-2|Opts:Stem=Down,StemLength=6,Beam=End
|Note|Dur:8th|Pos:1|Opts:Stem=Up,StemLength=6,Beam=First
|Note|Dur:16th|Pos:-2|Opts:Stem=Up,StemLength=7,Beam=End
|Bar|Style:Double
|User|BeamRestChords.fso|Pos:-2|DurNote2:Sixteenth|Color:1
|RestChord|Dur:32nd|Opts:Stem=Up,StemLength=7,HideRest|Dur2:4th|Pos2:1
|Rest|Dur:16th,Dotted|Visibility:Never
|RestChord|Dur:32nd|Opts:Stem=Up,StemLength=6,HideRest|Dur2:4th|Pos2:-2
|Rest|Dur:32nd|Visibility:Never
|User|BeamRestChords.fso|Pos:-2|DurNote2:Sixteenth|Color:1
|RestChord|Dur:32nd|Opts:Stem=Down,StemLength=6,HideRest|Dur2:4th|Pos2:1
|Rest|Dur:16th,Dotted|Visibility:Never
|RestChord|Dur:32nd|Opts:Stem=Down,StemLength=7,HideRest|Dur2:4th|Pos2:-2
|Rest|Dur:32nd|Visibility:Never
|Bar|Style:Double
!NoteWorthyComposer-End
If I add: nwcdraw.setPen('solid', 0)
early in your code, I get a bit more accuracy.
I have done some work on beams. Instead of using trigonometery, I just used slope/intercept, i.e,:I find it easier and it may avoid some rounding errors