Beam effect misbehaving due to trig & vectors

** YES, I AM USING RADIANS **

I’m trying to create an egon style helix beam effect using the code below:


function EFFECT:Init( data    )    self.Position = data:GetStart()
    self.EndPosition = data:GetOrigin()
    self.WeaponEnt = data:GetEntity()
    self.Attachment = data:GetAttachment()
    self.StartPosition = self:GetTracerShootPos( self.Position, self.WeaponEnt, self.Attachment )
    self.Direction =  self.EndPosition - self.StartPosition
    self.Direction:Normalize()
    self.Alpha = 255
    self.Width = 256
end


function EFFECT:Think()
    self.Alpha = self.Alpha - 1 * FrameTime()
    self.Width = math.Clamp(self.Width*0.99,4,64)
    if self.Alpha <= 0 then
        return false
    end
    return true
end


function EFFECT:Render()
    self.Length = (self.EndPosition - self.StartPosition):Length()


    render.SetMaterial( Material( "sprites/animglow02" ) ) 
    render.SetBlend(1)
    render.DrawSprite( self.EndPosition, self.Width,self.Width, Color(200+math.random(0,55), 200+math.random(0,55),200+math.random(0,55), math.Clamp(self.Alpha, 0,255)) )


    render.SetMaterial( Material( "sprites/physgbeamb" ) ) 
    render.SetBlend(1)


    local i;
    local incrememnts = 128
    local AngleDiv = 16
    local LaserDiv = math.floor(self.Length / incrememnts )*AngleDiv
    local rad = 128
    
    if LaserDiv > 0 then
        render.StartBeam(LaserDiv+1)
        render.AddBeam( self.StartPosition, math.random(0.9,1.1)*self.Width/4, 1, Color(100+math.random(0,155), 100+math.random(0,155),100+math.random(0,155), math.Clamp(self.Alpha, 0,255)) )
        for i=1,(LaserDiv/AngleDiv)-1,1 do
            for j=1,AngleDiv,1 do
                local scheisse = math.pi*2                                                 // 360 degrees = 2 pi radians
                local jangle = scheisse/(AngleDiv*j)                                    // "portions" by dividing by said number
                local EgonVec = Vector(0,math.sin(jangle),math.cos(jangle))*rad
                local laserNormal = self.Direction:Angle( )
                EgonVec:Rotate( laserNormal )
                render.AddBeam( self.StartPosition + self.Direction * ( (i + j/AngleDiv) * incrememnts ) + EgonVec , 4, CurTime(), Color(100+math.random(0,155), 100+math.random(0,155),100+math.random(0,155), math.Clamp(self.Alpha, 0,255)) )
            end
        end
        render.AddBeam( self.EndPosition, self.Width, 1, Color(100+math.random(0,155), 100+math.random(0,155),100+math.random(0,155), math.Clamp(self.Alpha, 0,255)) )
        render.EndBeam( )
        render.DrawBeam( self.StartPosition, self.EndPosition ,8,0, 1, Color(100+math.random(0,155), 100+math.random(0,155),100+math.random(0,155), math.Clamp(self.Alpha, 0,255)) )
    else
        render.DrawBeam( self.StartPosition, self.EndPosition ,math.random(0.9,1.1)*self.Width/4,0, 1, Color(100+math.random(0,155), 100+math.random(0,155),100+math.random(0,155), math.Clamp(self.Alpha, 0,255)) )
    end


    render.SetMaterial( Material( "sprites/animglow02" ) ) 
    render.SetBlend(1)
    render.DrawSprite( self.StartPosition, self.Width/2,self.Width/2, Color(200+math.random(0,55), 200+math.random(0,55),200+math.random(0,55), math.Clamp(self.Alpha, 0,255)) )






end


However i’m getting some strange patterns. Initially I was assuming it was because I wasn’t using radians so I changed that, but now that I am it’s actually misbehaving more. What it looks like :

https://dl.dropboxusercontent.com/u/888382/2014-07-19_00023.jpg

The lower beam represents the trace it should be around, the upper beam represents what the helix beam is outputting

this is what infected wars uses for the egon beam:



function ENT:DrawCurlyBeam( StartPos, EndPos, Angle )

	local TexOffset = CurTime() * 0.5

	local Forward	= Angle:Forward()
	local Right 	= Angle:Right()
	local Up 		= Angle:Up()
	
	local LastPos
	local Distance = StartPos:Distance( EndPos )
	local StepSize = 16
	local RingTightness = 0.05
		
	render.SetMaterial( matBeam )
	
	for i=0, Distance, StepSize do
	
		//local SizeMul = math.Clamp( (Distance-i) / Distance, 0.2, 1 )
	
		local sin = math.sin( CurTime() * -30 + i * RingTightness )
		local cos = math.cos( CurTime() * -30 + i * RingTightness )
		
		local Pos = StartPos + (Forward * i) + (Up * sin * 16) + (Right * cos * 16)
	
		if (LastPos) then
		
			render.DrawBeam( LastPos, Pos, 
							 (math.sin( i*0.02 )+1) * 4, 
							 TexOffset + i, 
							 TexOffset+Distance/128 + i, 
							 col_white )	 
		end
						 
		LastPos = Pos
	
	end

end