AppleWatch Tideグラフの縦幅調整

全体図

仕様

  • 釣行ソフトのTide情報に昼間のデータを追加しました

   

  • 8月28日:日の出、日の入り時間と昼間時間を表示しました

  

 

昼間の計算

  • 緯度経度を取得
    • Teidの”na"データを使う
      • 清水、小浜、金沢、敦賀、大阪、境、神戸を追加しました
      • let na = [["静岡/清水", 35.01, 138.30,  95],

                  ["静岡/舞阪", 34.41, 137.37,  70],

                  ["愛知/師崎", 34.42, 136.59, 125],

                  ["愛知/武豊", 34.51 ,136.56 ,132],

                  ["三重/五ケ所",34.19, 136.40, 103],

                  ["三重/鳥羽", 34.29, 136.51, 120],

                  ["三重/的矢", 34.22, 136.52, 110],

                  ["三重/尾鷲", 34.04, 136.13, 104],

                  ["福井/小浜", 35.30, 135.44,  18],

                  ["福井/金沢", 36.37, 136.36,  20],

                  ["福井/敦賀", 35.40, 136.04,  18],

                  ["大阪/大阪", 34.39, 135.26,  95],

                  ["大阪/堺 ", 34.35, 135.28,  95],

                  ["兵庫/神戸", 34.41 ,135.12,  95]

        ]

    • 選択された場所から緯度と経度を取得する
      • let latAy = na[tideSelectionValue][1] as! Double

        let lngAy = na[tideSelectionValue][2] as! Double

        lat = dg2dc( latAy )

        lon = dg2dc( lngAy )

         

  • 日の出・日の入りを計算

    • 指定された場所の緯度と経度を用いて計算し、戻り値として日の出時刻と日の入り時刻の2つのDouble値を返します。

      • //......................................

        //参考PG:http://k-ichikawa.blog.enjoy.jp/etc/HP/js/sunRise/srs1.html

        //......................................

        func calcA( m: Int, d1: Int ) -> (Double, Double) {

            let MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; //日数

            var T: Double

            let tsta: Double

            let tend: Double

            

            //TOKYOU

            var lat = 35.68

            var lon = 139.77

            

            let latAy = na[tideSelectionValue][1] as! Double

            let lngAy = na[tideSelectionValue][2] as! Double

            lat = dg2dc( latAy )

            lon = dg2dc( lngAy )

             

         

            var jd2 = d1

            for i in 0..<m-1 {

                jd2 += MD[i]

            }

            let jd: Double = Double( jd2 ) + 0.5

            let nd = 365.0;

            let w  = 2.0 * Double.pi / nd

            let wj = w * Double(jd)

            

            let delta: Double = 0.33281 - 22.984*cos(wj) - 0.34990*cos(2*wj) - 0.13980*cos(3*wj)

            + 3.7872*sin(wj) + 0.03250*sin(2*wj) + 0.07187*sin(3*wj)

            

            let ee: Double =   0.0072*cos(wj) - 0.0528*cos(2*wj) - 0.0012*cos(3*wj)

            - 0.1229*sin(wj) - 0.1565*sin(2*wj) - 0.0041*sin(3*wj)

            

            let phi:Double = lat*Double.pi/180

            let del:Double = delta*Double.pi/180

            

           //太陽の視半径と大気の屈折を考慮

            let t: Double = acos*1 /  (cos(del) * cos(phi))) * 180 / Double.pi

        //    let t: Double = acos(-tan(del)*tan(phi))*180/Double.pi

            //日の出

            T = (-t + 180)/15;

            tsta = T - (lon - 135)/15.0 - ee

            //日の入り

            T = (t + 180)/15

            tend = T - (lon - 135)/15.0 - ee

            //tmid = (tsta + tend)/2;

            return (tsta, tend)

        }

  • 組み付け
    • 昼間時間帯(黄色)とTide表の枠(白色)を表示

       

    • 昼間の時間帯を表示するには、gridBoxを呼び出します。引き数は「日の出」「日の入り」です
      • func gridBox(dosu01:Double, dosu02:Double) -> some View {

            gridBox1(width: 140, height: 100, dosu01:dosu01, dosu02:dosu02 )

                .offset(x: 10, y: -5)

                .fill(Color(red: 0.3, green: 0.3, blue: 0.1))

        }

        func gridBox1(width: CGFloat, height: CGFloat, dosu01:Double, dosu02:Double ) -> some Shape {

            Path { path in

                var i = width / 24 * dosu01

                path.move(to: CGPoint(x: i, y: 0))

                path.addLine(to: CGPoint(x: i , y: height))

                i = width / 24 * dosu02

                path.addLine(to: CGPoint(x: i  , y: height))

                path.addLine(to: CGPoint(x: i, y: 0))

                path.closeSubpath()

            }

        }

    • Tideグラフと現在の時間を追加し表示します。この機能については、以前の投稿で確認ねがいます

       

Tideグラフの横幅調整 8月31日追加qiita.com

  • 上記の情報から横幅を取り出し、画面いっぱいに表示する

   

  • let widthCaseSize = WKInterfaceDevice.current().screenBounds.size.width - 10

     

    ZStack {

        if selectionOffset != 0 {

            //日の出、日の入

            let re = calcA(m: month , d1: day )

            //昼間時間帯

            gridBox( dosu01:re.0, dosu02:re.1, width:widthCaseSize )

            let openTime = Int( re.0 )

            let openMinu = (Double(re.0) - Double(openTime)) * 60.0

            let closeTime = Int( re.1 )

            let closeMinu = (Double(re.1) - Double(closeTime)) * 60.0

            Text(" \(openTime):\(Int(openMinu))           \(closeTime):\(Int(closeMinu))")

                .offset(x: 0, y: -44 )

            //基本枠

            gridLine(width:widthCaseSize)

            //Tide値取得

            let returnTideLintPoint = tideLineSet( year:year, month:month, day: day, fg24:false )

            //Tideグラフ作成

            ForEach(0..<73) { num in

                tideLine( num:num , tid:returnTideLintPoint, width:widthCaseSize )

            }

            //現在時間表示

            gridTimeLine( hour:hour, miut:miut, width:widthCaseSize )

        }

     

    •  横幅(widthCaseSize)を使いTideグラフを作成する

Tideグラフの縦幅調整 9月1日追加

  • AppleWatchの種類によって画面サイズが異なるので8月31日に横幅を調整しました。9月1日は、縦幅を調整しました。

  

  • //縦幅を取り出し、「昼間時間帯、基本枠、Tideグラフ作成、現在時刻」描画時に情報を送る

    let heightCaseSize = WKInterfaceDevice.current().screenBounds.size.height

     

    ZStack {

        if selectionOffset != 0 {

            //日の出、日の入

            let re = calcA(m: month , d1: day )

            //昼間時間帯

            gridBox( dosu01:re.0, dosu02:re.1, width:widthCaseSize, height:heightCaseSize )

            let openTime = Int( re.0 )

            let openMinu = (Double(re.0) - Double(openTime)) * 60.0

            let closeTime = Int( re.1 )

            let closeMinu = (Double(re.1) - Double(closeTime)) * 60.0

            Text(" \(openTime):\(Int(openMinu))           \(closeTime):\(Int(closeMinu))")

                .offset(x: 0, y: -heightCaseSize * 0.2 )

            //基本枠

            gridLine(width:widthCaseSize, height:heightCaseSize )

            //Tide値取得

            let returnTideLintPoint = tideLineSet( year:year, month:month, day: day, fg24:false )

            //Tideグラフ作成

            ForEach(0..<73) { num in

                tideLine( num:num , tid:returnTideLintPoint, width:widthCaseSize, height:heightCaseSize )

            }

            //現在時間表示

            gridTimeLine( hour:hour, miut:miut, width:widthCaseSize, height:heightCaseSize  )

        }

 

今後について

  • 動きを確認したら、GitHubに上げます → 8月27日:アップデートしました
  • 日の出、日の入り時間を数値で表示できれば嬉しい → 8月28日:追記しました

       

  • 釣り関連表に統合されていますが、この機能単体でリリースするか思案しています
ここまで読んでいただき、ありがとうございます

*1:-51 / 60 * Double.pi / 180-sin(del)*sin(phi

プライバシーポリシー |ページトップへ

`