简体   繁体   English

当知道上一个和下一个潮汐时获取当前潮汐高度

[英]Get current tide height when previous and next tides are known

I'm trying to calculate the current tide height based on the height of the previous tide, the height of the next tide, and the time difference of the two.我试图根据上一个潮汐的高度,下一个潮汐的高度以及两者的时间差来计算当前的潮汐高度。

I've tried to use this formula as a start but I think I either have something wrong in the formula or the formula won't work based on only having the previous and next tides (or both, and I'm way off):我尝试使用这个公式作为开始,但我认为我要么在公式中有问题,要么公式不会基于仅具有前一个和下一个潮汐(或两者,我已经离开):

在此处输入图像描述

Found here: https://www.dummies.com/article/academics-the-arts/math/trigonometry/measure-tidal-change-using-a-trigonometry-graph-187108/在这里找到: https://www.dummies.com/article/academics-the-arts/math/trigonometry/measure-tidal-change-using-a-trigonometry-graph-187108/

I'm trying to solve this in Kotlin but can translate from any other language if given a working example.我试图在 Kotlin 中解决这个问题,但如果给出一个工作示例,可以从任何其他语言翻译。

My code looks like this:我的代码如下所示:

val previousTideHeight = 5.3
val nextTideHeight = -.3
val timeBetweenTides = 60 * 60 * 6 // 6 hours in seconds
val timeSincePrevTide = 60 * 60 * 3 // 3 hours in seconds
val tideHeightDifference = previousTideHeight - nextTideHeight
val averageTideHeight = tideHeightDifference / 2
val tideAmplitude = Math.max(Math.abs(averageTideHeight - previousTideHeight), Math.abs(averageTideHeight - nextTideHeight))
val currentHeight = (tideAmplitude * Math.sin(Math.PI / timeBetweenTides) * timeSincePrevTide) + averageTideHeight

After messing with everything for a little I ended up with a formula that seems to be working but would love any feedback on it as I'm not totally certain how it all works.在稍微弄乱了所有内容之后,我最终得到了一个似乎有效但希望得到任何反馈的公式,因为我不完全确定它是如何工作的。

val previousTideHeight = -1.3
val nextTideHeight = 5.2
val hoursBetweenTides = 6
val hoursSincePrevTide = 0

val timeBetweenTides = 60 * 60 * hoursBetweenTides
val timeSincePrevTide = 60 * 60 * hoursSincePrevTide

// We need to shift the graph horizontally based on the time since the previous tide
// and we need to produce a negative number so that we can get a value below the equilibrium
val timeShift = (timeSincePrevTide - (timeBetweenTides / 2)) * 2

// If the tide is going down we need to shift the graph the
// other direction to catch the down slope
val tideDirectionMultiplier = if (previousTideHeight > nextTideHeight) -1 else 1

val tideHeightDifference = previousTideHeight + nextTideHeight
val averageTideHeight = tideHeightDifference / 2

val tideAmplitude = Math.max(Math.abs(averageTideHeight - previousTideHeight), Math.abs(averageTideHeight - nextTideHeight))
val currentHeight = (tideAmplitude * Math.sin((Math.PI / (timeBetweenTides * 2)) * (timeShift * tideDirectionMultiplier))) + averageTideHeight

return currentHeight

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 android kotlin android 版本 8 中单击按钮后如何获取当前年份、前几年和明年 - How to get current year , previous years and next years after click on button In android kotlin which will also work fine in under android version 8 获取流集合中的当前值和上一个值 - Get current and previous value in flow's collect Rxjava - 如何获取当前和上一个项目? - Rxjava - How to get the current and the previous item? 如何在 Android Studio 中使用 Kotlin 从 Firestore 数据库中获取下一条和上一条数据? - How to get the Next and Previous piece of data from the Firestore Database using Kotlin in Android Studio? 按前进按钮或上一个按钮时获取一周的开始日期和结束日期 - Get startDate and endDate of week when pressing forward button or previous button 尝试在Android应用程序(Kotlin)中按下按钮时获取最后的已知位置 - Trying to get last known location when a button is pressed in Android app (Kotlin) 从第二个片段返回时如何获取前一个片段的值 - How to get values of previous fragment when return from second fragment 视图的一部分在屏幕外时获取视图高度? - Get view height when part of the view is off screen? IntelliJ :(键盘快捷方式)跳转到下一个/上一个建议 - IntelliJ: (Keyboard shortcut to) jump to next / previous suggestion 当设备锁定在 android 中时,无法以特定间隔获取当前位置 - Not able to get current location at certain interval when device locked in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM