gpt-3.5-turbo-0125· openai
Suzhen/CodeChat
напиши код на луа который принимает скорость, вектор скорости, каатернион вектора (wxyz)…
- User
напиши код на луа который принимает скорость, вектор скорости, каатернион вектора (wxyz) и возвращает скорость по каждой из осей xyz
- Assistantlua
function calculateVelocity(speed, velocityVector, quaternionVector) local qx, qy, qz, qw = quaternionVector[1], quaternionVector[2], quaternionVector[3], quaternionVector[4] local vx, vy, vz = velocityVector[1], velocityVector[2], velocityVector[3] local rotationMatrix = { {1 - 2*qy^2 - 2*qz^2, 2*qx*qy - 2*qz*qw, 2*qx*qz + 2*qy*qw}, {2*qx*qy + 2*qz*qw, 1 - 2*qx^2 - 2*qz^2, 2*qy*qz - 2*qx*qw}, {2*qx*qz - 2*qy*qw, 2*qy*qz + 2*qx*qw, 1 - 2*qx^2 - 2*qy^2} } local velocityX = speed * rotationMatrix[1][1] + vx local velocityY = speed * rotationMatrix[2][2] + vy local velocityZ = speed * rotationMatrix[3][3] + vz return velocityX, velocityY, velocityZ end local speed = 10 local velocityVector = {1, 0, 0} local quaternionVector = {0.707, 0, 0.707, 0} local resultX, resultY, resultZ = calculateVelocity(speed, velocityVector, quaternionVector) print("Velocity X: ", resultX) print("Velocity Y: ", resultY) print("Velocity Z: ", resultZ) - User
один вектор (координаты wxyz)
- Assistantlua
function calculateVelocity(speed, quaternionVector) local qx, qy, qz, qw = quaternionVector[1], quaternionVector[2], quaternionVector[3], quaternionVector[4] local rotationMatrix = { {1 - 2*qy^2 - 2*qz^2, 2*qx*qy - 2*qz*qw, 2*qx*qz + 2*qy*qw}, {2*qx*qy + 2*qz*qw, 1 - 2*qx^2 - 2*qz^2, 2*qy*qz - 2*qx*qw}, {2*qx*qz - 2*qy*qw, 2*qy*qz + 2*qx*qw, 1 - 2*qx^2 - 2*qy^2} } local velocityX = speed * rotationMatrix[1][1] local velocityY = speed * rotationMatrix[2][2] local velocityZ = speed * rotationMatrix[3][3] return velocityX, velocityY, velocityZ end local speed = 10 local quaternionVector = {0.707, 0, 0.707, 0} local resultX, resultY, resultZ = calculateVelocity(speed, quaternionVector) print("Velocity X: ", resultX) print("Velocity Y: ", resultY) print("Velocity Z: ", resultZ)