apply_obj_transform Subroutine

public subroutine apply_obj_transform(mesh, scale, rotation_deg, offset)

OBJ メッシュの全頂点にスケール→回転→平行移動を適用し再初期化する。 変換順序: v_new = R(rotation) * (v_old * scale) + offset 回転は度単位で x→y→z の順に外因性 (extrinsic) 回転を適用する。

Arguments

Type IntentOptional Attributes Name
type(mesh_type), intent(inout) :: mesh

変換対象の三角形メッシュ。

real(kind=dp), intent(in) :: scale

一様スケーリング係数。

real(kind=dp), intent(in) :: rotation_deg(3)
real(kind=dp), intent(in) :: offset(3)

Calls

proc~~apply_obj_transform~~CallsGraph proc~apply_obj_transform apply_obj_transform proc~init_mesh init_mesh proc~apply_obj_transform->proc~init_mesh proc~update_mesh_geometry update_mesh_geometry proc~init_mesh->proc~update_mesh_geometry proc~build_collision_grid build_collision_grid proc~update_mesh_geometry->proc~build_collision_grid proc~cross~2 cross proc~update_mesh_geometry->proc~cross~2 proc~cell_id~2 cell_id proc~build_collision_grid->proc~cell_id~2 proc~coord_to_cell~2 coord_to_cell proc~build_collision_grid->proc~coord_to_cell~2

Called by

proc~~apply_obj_transform~~CalledByGraph proc~apply_obj_transform apply_obj_transform proc~build_mesh_from_config build_mesh_from_config proc~build_mesh_from_config->proc~apply_obj_transform proc~load_or_init_run_state load_or_init_run_state proc~load_or_init_run_state->proc~build_mesh_from_config program~main main program~main->proc~load_or_init_run_state

Source Code

  subroutine apply_obj_transform(mesh, scale, rotation_deg, offset)
    type(mesh_type), intent(inout) :: mesh
    real(dp), intent(in) :: scale
    real(dp), intent(in) :: rotation_deg(3)
    real(dp), intent(in) :: offset(3)
    real(dp), parameter :: deg2rad = acos(-1.0d0)/180.0d0
    real(dp) :: rx, ry, rz, cx, sx, cy, sy, cz, sz
    real(dp) :: R(3, 3), v(3)
    real(dp), allocatable :: tv0(:, :), tv1(:, :), tv2(:, :)
    integer(i32) :: i, n

    rx = rotation_deg(1)*deg2rad
    ry = rotation_deg(2)*deg2rad
    rz = rotation_deg(3)*deg2rad
    cx = cos(rx); sx = sin(rx)
    cy = cos(ry); sy = sin(ry)
    cz = cos(rz); sz = sin(rz)

    ! R = Rz * Ry * Rx (extrinsic x→y→z)
    R(1, 1) = cy*cz; R(1, 2) = sx*sy*cz - cx*sz; R(1, 3) = cx*sy*cz + sx*sz
    R(2, 1) = cy*sz; R(2, 2) = sx*sy*sz + cx*cz; R(2, 3) = cx*sy*sz - sx*cz
    R(3, 1) = -sy; R(3, 2) = sx*cy; R(3, 3) = cx*cy

    n = mesh%nelem
    allocate (tv0(3, n), tv1(3, n), tv2(3, n))
    do i = 1, n
      v = mesh%v0(:, i)*scale
      tv0(:, i) = matmul(R, v) + offset
      v = mesh%v1(:, i)*scale
      tv1(:, i) = matmul(R, v) + offset
      v = mesh%v2(:, i)*scale
      tv2(:, i) = matmul(R, v) + offset
    end do
    call init_mesh(mesh, tv0, tv1, tv2)
  end subroutine apply_obj_transform