program coordinate_transformation_example
implicit none
real :: x(3), y(3), z(3) ! 原始坐标系的基向量
real :: x1(3), y1(3), z1(3) ! 局部坐标系的基向量
real :: P(3) ! 点P在原始坐标系下的坐标
real :: P1(3) ! 点P在局部坐标系下的坐标差
real :: P_local(3) ! 点P在局部坐标系下的新坐标
! 设置原始坐标系的基向量
x = [1.0, 0.0, 0.0]
y = [0.0, 1.0, 0.0]
z = [0.0, 0.0, 1.0]
! 设置局部坐标系的基向量
x1 = [0.0, 1.0, 0.0]
y1 = [1.0, 0.0, 0.0]
z1 = [0.0, 0.0, 1.0]
! 设置点P在原始坐标系下的坐标
P = [1.3, 0.1, 0.2]
! 计算点P在局部坐标系下的坐标差
P1 = P - [-1.0, 0.0, 0.0]
! 计算点P在局部坐标系下的新坐标
P_local = P1(1) * x1 + P1(2) * y1 + P1(3) * z1
! 输出结果
print *, "Point P in local coordinate system: ", P_local
end program coordinate_transformation_example
function dot_product(a,b) result(c)
implicit none
real :: a(3), b(3), c(3)
c(1) = a(2)*b(3) - a(3)*b(2)
c(2) = a(3)*b(1) - a(1)*b(3)
c(3) = a(1)*b(2) - a(2)*b(1)
end function dot_product