incorrect orientation of the point in space

Good afternoon.

I want to write a script to rotate the camera, using Rotation_script()

Imagine that there is a rail on which slides the carriage and the carriage attached to the camera.
When moving the carriage along the rails, the camera rotates and the subject is always in the center of the frame.
The location of the rails with the camera and the subject in the scene space can be different.

Initial data.

The camera in the initial shooting position $Cam_Ferst, the camera end shooting position $Cam_Second.
The subject represented by the object Point $T1_CenterScene.

The stage is in the file TEST01.max

The script ---
******************************************************************
-- fetchMaxFile quiet:true
try (DestroyDialog parent_dialog) catch()
rollout parent_dialog "Parent" width:144 height:120
(
global point01= undefined
global point02= undefined
global vec1 = undefined
global vec2 = undefined
global iniDegr = undefined -- первоначальный угол поворота вертикальной оси камеры относительно траектории движения
global myController = undefined
global FerstAngel = undefined-- угол первой камеры в нулевом кадре анимации
global SecondAngel = undefined-- угол вторй камеры в нулевом кадре анимации
global iniDist = undefined-- расстояние между камерами слайдера в нулевом кадре анимации
global iniAngel = undefined-- первоначальная разность углов
global Fcam = undefined -- переменная содержащая первую камеру слайдера (на начальном положении)
global Cam_Ferst = undefined
global Cam_Second = undefined
-- функция нахождения угла между векторами
fn GetVectorsAngle v1 v2 =
(
theAngle = acos(dot (normalize v1) (normalize v2))
)
--************** органы управления слайдером ***********************

-- spinner spnPause "Pause: " pos:[16,16] width:80 height:16 range:[0,10,0.2] scale:0.01
-- label lblSek "Sek." pos:[112,16] width:24 height:18

checkbox chkCenter "Center" pos:[16,40] width:56 height:18

spinner spnAngle "Angle:" pos:[16,64] width:80 height:16 range:[0,180,90] scale:0.1 enable:false
label lblDeg "Deg." pos:[104,64] width:24 height:18

button btnChek "CHEK" pos:[8,96] width:54 height:18

button btnSolve "SOLVE" pos:[72,96] width:54 height:18

on parent_dialog open do
(

-- build spline trajectories $CamPathLine
poin01 =$Cam_Ferst.pos
poin02 =$Cam_Second.pos
theShape = splineShape()
addnewSpline theShape
addKnot theShape 1 #corner #line $Cam_Ferst.pos
addKnot theShape 1 #corner #line $Cam_Second.pos
updateShape theShape
theShape.name ="CamPathLine"

-- build point T2_VerticalOs. Dot represents the axis of rotation of the camera
thePlane = Plane()
p1 = point pos:$Cam_Ferst.pos
p2 = point pos:$Cam_Second.pos
p3 = point pos:$T1_CenterScene.pos
ctrl = transform_script()
thePlane.transform.controller = ctrl
ctrl.addNode"p1" p1
ctrl.addNode"p2" p2
ctrl.addNode"p3" p3
txt ="v1 = normalize (p2.pos-p1.pos)\n"
txt +="v2 = normalize (p3.pos-p1.pos)\n"
txt +="nv1 = normalize (cross v1 v2)\n"
txt +="nv2=normalize(cross nv1 v1)\n"
txt +="matrix3 v1 nv2 nv1 ((p1.pos+p2.pos+p3.pos)/3)"
ctrl.setExpression txt
T2 = point name:"T2_VerticalOs"
T2.transform = thePlane.transform
delete thePlane
delete p1
delete p2
delete p3
T2.pos = $Cam_Ferst.pos
in coordsys local $T2_VerticalOs.rotation.x_rotation =270
in coordsys local $T2_VerticalOs.rotation.y_rotation =270

T3 = point name:"T3_RotController" size:54
T3.transform = $T2_VerticalOs.transform
pc = path_constraint()
T3 .position.controller = pc
pc.path = $CamPathLine
$Cam_Ferst.parent = $T3_RotController

T4 = point name:"T4_RotController"
T4.transform = $T2_VerticalOs.transform
pc = path_constraint()
T4 .position.controller = pc
pc.path = $CamPathLine

FerstAngel = (quatToEuler2 (in coordsys $T2_VerticalOs $Cam_Ferst.rotation)).y
SecondAngel= (quatToEuler2 (in coordsys $T2_VerticalOs $Cam_Second.rotation)).y
iniAngel = abs (FerstAngel - SecondAngel)
iniDist = distance $Cam_Ferst.pos $Cam_Second.pos
)

on spnAngle changed val do
(
in coordsys $T2_VerticalOs $Cam_Ferst.rotation.y_rotation = spnAngle.value
)

on chkCenter changed theState do
(
if (chkCenter.checked == false) then
(
select $T3_RotController
spnAngle.enabled = true
spnAngle.indeterminate=false
ctrl = Euler_XYZ()
$T3_RotController.rotation.controller = ctrl
)
else
(
select $T3_RotController
spnAngle.enabled = false
spnAngle.indeterminate=true
ctrl = Rotation_script()
$T3_RotController.rotation.controller = ctrl
ctrl.addNode"Cam_Ferst" $Cam_Ferst
ctrl.addNode "Cam_Second" $Cam_Second
ctrl.addNode "T2_VerticalOs" $T2_VerticalOs
ctrl.addNode "T3_RotController" $T3_RotController
ctrl.addNode "T4_RotController" $T4_RotController
ctrl.addConstant "FerstAngel" FerstAngel
ctrl.addConstant "SecondAngel" SecondAngel
ctrl.addConstant "iniDist" iniDist
ctrl.addConstant "iniAngel" iniAngel
txt = "tD = distance T4_RotController Cam_Second \n"
txt += "RDR =(iniAngel*(1-tD/iniDist))as float \n"
txt += "if (FerstAngel > SecondAngel) then ( \n"
txt += "ffA =FerstAngel+RDR \n"
txt += "eulerToQuat ( eulerAngles 0 ffA 0) \n"
txt += ") \n"
txt += "else ( \n"
txt += "ffA =FerstAngel-RDR\n"
txt += "eulerToQuat (eulerAngles 0 ffA 0)\n"
txt += ") "
ctrl.setExpression txt
)
)
)
createDialog parent_dialog pos:[100,100] style:#(#style_titlebar, #style_border, #style_sysmenu, #style_minimizebox)

******************************************************************

To set the scene TEST01.max , run the script and click the checkbox "Center"

Constants are described in the body of the script Rotation_script () for object$T3_RotController:

FerstAngel = (quatToEuler2 (in coordsys $T2_VerticalOs $Cam_Ferst.rotation)).y
SecondAngel= (quatToEuler2 (in coordsys $T2_VerticalOs $Cam_Second.rotation)).y
iniAngel = abs (FerstAngel - SecondAngel)
iniDist = distance $Cam_Ferst.pos $Cam_Second.pos

I expected that the orientation of the point $T3_RotController will coincide with the orientation of the point $T2_VerticalOs,
and the camera will rotate normally, but this does not happen. Can someone explain why this is happening?

AttachmentSize
test01.max256 KB