function Util.makeOrientation(a,D)D=D.unit local r=dot(ux,D)if r>.99999 then return cframe(a,a-uz)elseif r<-0.99999 then return cframe(a,a+uz)else local s=cross(ux,D)local Y=1+r local N=sqrt(s.magnitude^2+Y*Y)s=s/N Y=Y/N return cframe(a.x,a.y,a.z,s.x,s.y,s.z,Y)end end return Util

function Util.makeOrientation(sourcePos, dir)
    -- Construct CFrame to rotate parts from x-axis alignment (where they are constructed) to
    -- the world orientation of the arc from a quaternion rotation that describes the
    -- rotation of ux-->axis
    dir = dir.unit

    -- Proportionate angle between ux and direction:
    local angleUxAxis = dot(ux, dir)

    if (angleUxAxis > 0.99999) then
        return cframe(sourcePos, sourcePos - uz)
    elseif (angleUxAxis < -0.99999) then
        return cframe(sourcePos, sourcePos + uz)
    else
        local q = cross(ux, dir)
        local qw = 1 + angleUxAxis
        local qnorm = sqrt(q.magnitude ^ 2 + qw * qw)
        q = q / qnorm
        qw = qw / qnorm
        return cframe(sourcePos.x, sourcePos.y, sourcePos.z, q.x, q.y, q.z, qw)
    end
end

return Util
