[英]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.