任意の緯度・経度情報から、別の箇所の緯度・経度情報の「方位」を計算するAppleScriptです。
v1では、Satimage OSAXのインストールが必要でしたが、自前でObjective-Cで書いた「atan2だけを計算するフレームワーク」に置き換えたものです。
–> trigonometry.framework (To ~/Library/Frameworks/)
北を0として、西に向かうとマイナス、東に向かうとプラスの値で角度(方位)を返します。この手の計算に必須のatan2関数がAppleScriptに標準装備されていないため、atan2を呼び出すだけの簡単なCocoa FrameworkをObjective-Cで記述して、呼び出してみました。
AppleScript名:1箇所から別の箇所の方位を求める v2 |
— Created 2018-05-10 by Takaaki Naganoya — 2017-2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "trigonometry" –(for atan2 calculation) use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html set coord1 to {latitude:35.73677496, longitude:139.63754457} –Nakamurabashi Sta. set coord2 to {latitude:35.78839012, longitude:139.61241447} –Wakoshi Sta. set dirRes1 to calcDirectionBetweenTwoPlaces(coord1, coord2) of me –> -25.925429877542 set coord2 to {latitude:35.7227821, longitude:139.63860897} –Saginomiya Sta. set dirRes2 to calcDirectionBetweenTwoPlaces(coord1, coord2) of me –> 175.649833487804 set coord2 to {latitude:35.73590542, longitude:139.62986745} –Fujimidai Sta. set dirRes3 to calcDirectionBetweenTwoPlaces(coord1, coord2) of me –> -96.385293928667 set coord2 to {latitude:35.73785024, longitude:139.65339321} –Nerima Sta. set dirRes4 to calcDirectionBetweenTwoPlaces(coord1, coord2) of me –> 85.959474671834 set coord2 to {latitude:35.71026838, longitude:139.81215754} –Tokyo Sky Tree set dirRes5 to calcDirectionBetweenTwoPlaces(coord1, coord2) of me –> 96.826542737106 –位置情報1から位置情報2の方角を計算。北が0度 on calcDirectionBetweenTwoPlaces(coord1, coord2) load framework –BridgePlus set deltaLong to (longitude of coord2) – (longitude of coord1) set yComponent to bPlus’s sinValueOf:deltaLong set xComponent to (bPlus’s cosValueOf:(latitude of coord1)) * (bPlus’s sinValueOf:(latitude of coord2)) – (bPlus’s sinValueOf:(latitude of coord1)) * (bPlus’s cosValueOf:(latitude of coord2)) * (bPlus’s cosValueOf:deltaLong) set radians to (current application’s calcAtan2’s atan2Num:yComponent withNum:xComponent) as real set degreeRes to (radToDeg(radians) of me) return degreeRes end calcDirectionBetweenTwoPlaces on radToDeg(aRadian) return aRadian * (180 / pi) end radToDeg |
More from my site
(Visited 67 times, 1 visits today)