return function(c,m,V,R)local O=c:pointToObjectSpace(m)local L=O.Unit local Z=O.Magnitude local D=(Vector3.new(0,0,-1)):Cross(L)local f=math.acos(-L.Z)local d=c*CFrame.fromAxisAngle(D,f)if Z<math.max(R,V)-math.min(R,V)then return d*CFrame.new(0,0,(math.max(R,V)-math.min(R,V))-Z),-math.pi/2,math.pi elseif Z>V+R then return d,math.pi/2,0 else local c=-math.acos(((-(R*R)+V*V)+Z*Z)/((2*V)*Z))local m=math.acos(((R*R-V*V)+Z*Z)/((2*R)*Z))return d,c+math.pi/2,m-c end end




return function (originCF, targetPos, l1, l2)	
	-- Build intial values for solving
	local localized = originCF:pointToObjectSpace(targetPos)
	local localizedUnit = localized.Unit
	local l3 = localized.Magnitude
	
	-- Build a "rolled" planeCF for a more natural arm look
	local axis = Vector3.new(0, 0, -1):Cross(localizedUnit)
	local angle = math.acos(-localizedUnit.Z)
	local planeCF = (originCF * CFrame.fromAxisAngle(axis, angle))
	
	-- Case: point is to close, unreachable
	-- Action: push back planeCF so the "hand" still reaches, angles fully compressed
	if l3 < (math.max(l2, l1) - math.min(l2, l1)) then
		return planeCF * CFrame.new(0, 0,  math.max(l2, l1) - math.min(l2, l1) - l3), -math.pi/2, math.pi
		
	-- Case: point is to far, unreachable
	-- Action: for forward planeCF so the "hand" still reaches, angles fully extended
	elseif l3 > (l1 + l2) then
		--return planeCF * CFrame.new(0, 0, l1 + l2 - l3), math.pi/2, 0
		return planeCF, math.pi/2, 0
		
	-- Case: point is reachable
	-- Action: planeCF is fine, solve the angles of the triangle
	else
		local a1 = -math.acos((-(l2 * l2) + (l1 * l1) + (l3 * l3)) / (2 * l1 * l3))
		local a2 = math.acos(((l2  * l2) - (l1 * l1) + (l3 * l3)) / (2 * l2 * l3))

		return planeCF, a1 + math.pi/2, a2 - a1
	end
end
