面法線ベクトルから接線2軸を構築する。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | normal(3) | |||
| real(kind=dp), | intent(out) | :: | tangent1(3) | |||
| real(kind=dp), | intent(out) | :: | tangent2(3) |
subroutine build_tangent_basis(normal, tangent1, tangent2) real(dp), intent(in) :: normal(3) real(dp), intent(out) :: tangent1(3), tangent2(3) real(dp) :: n(3), ref(3), norm_n, norm_t1 norm_n = sqrt(sum(normal*normal)) if (norm_n <= 0.0_dp) error stop "surface normal norm must be > 0" n = normal/norm_n if (abs(n(1)) < 0.9_dp) then ref = [1.0_dp, 0.0_dp, 0.0_dp] else ref = [0.0_dp, 1.0_dp, 0.0_dp] end if tangent1 = cross3(n, ref) norm_t1 = sqrt(sum(tangent1*tangent1)) if (norm_t1 <= 0.0_dp) error stop "failed to build tangent basis" tangent1 = tangent1/norm_t1 tangent2 = cross3(n, tangent1) end subroutine build_tangent_basis