#Get first pos
execute store result score @s pos_z run data get entity @s Pos[2] 100

#Get second pos
execute store result entity @s Rotation[0] float 1 run scoreboard players get $cos main
execute at @s run tp @s ^ ^ ^1
execute store result score @s pos_x run data get entity @s Pos[2] 100

#Calculate length
scoreboard players operation @s pos_z -= @s pos_x
scoreboard players operation @s pos_z *= $-1 main

#Result
scoreboard players operation $cos main = @s pos_z
kill @s