简体   繁体   English

使用正弦波获取交叉点

[英]Get Points of Intersection with Sine Wave

I have a particle at a fixed position X and fixed amplitude AMP that travels on a sin wave. 我有一个在固定位置X和固定振幅AMP上运行的正弦波粒子。

I'd like to be able to dynamically change the period of the target sine wave WITHOUT moving the particle. 我希望能够在不移动粒子的情况下动态更改目标正弦波的周期。 (When I change the period, its X position doesn't line up to the same Y position of the graph with a different period, so it jumps all over the place. (当我更改周期时,其X位置不会与具有不同周期的图形的相同Y位置对齐,因此它会在整个位置上跳转。

I have a solution for this - Find where the graph with the new period intersects with the graph of the old period and create an X-offset, lining these two figures up. 我对此有一个解决方案-查找新时期的图形与旧时期的图形相交的位置,并创建X偏移,将这两个数字对齐。

For any given y on a sin wave, there will be 2 corresponding X values per period. 对于正弦波上任何给定的y,每个周期将有2个相应的X值。 I'm trying to get these two values. 我正在尝试获得这两个值。 I'll then compare the derivatives to choose which one I want. 然后,我将比较衍生产品以选择所需的衍生产品。

However, I don't know how to get both of these values. 但是,我不知道如何获得这两个值。 Any ideas? 有任何想法吗?

Here's an image of what I'm after: Sin Wave Logic 这是我所追求的图像: 正弦波逻辑

If you have a sine-wave defined by 如果您有定义为的正弦波

y = sin(a*(x+c))+d

then you can reverse it by 那么你可以通过

x = (arcsin(y-d)-c)/a

for a given a. 给定的

This yields the solution in the range of [-pi;pi] 这产生在π-π范围内的解。

The other solution you are looking for is then 2*pi-x 您正在寻找的另一个解决方案是2*pi-x

If you allow a little cheating, you can use a cross-fading effect to get a smooth transition from f(t) to g(t) via 如果您允许一些作弊,则可以使用交叉淡入淡出效果,以通过以下方式从f(t)到g(t)平滑过渡

h(s,t)=(1-s)*f(t)+s*g(t)

while s as a function of t is between 0 and 1 and use something like 而s作为t的函数在0到1之间,并且使用类似

y = h( (t-ts)/d, t)

for the time period from ts to ts+d . tsts+d的时间范围内。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM