Archive for January, 2010

Trigonometric Parameter Model

January 8, 2010 Comments off

The question that generated this topic was very similar to a problem I worked on recently. It deals with the trend of the last few posts on creating simple models that fit data. Suppose we have a parameter, z. It does not make any difference what z is; it could be depth or some other value. Suppose an object moves along a path parameterized by some angle, Θ, in [0,2∏].  The maximum value of z is given as zmax. An additional parameter, α, is defined with α in [0,1]. This is used as a multiplier onto zmax to describe the fraction of that value that must be obtained at certain angles.

A model, f(Θ), is to be created that fits the following data.

f(0) = αzmax
f(∏/2) = 0
f(∏) = azmax
f(3∏/2) = zmax
f(2∏) = f(0)

The model is symmetric moving from 3∏/2 to ∏. The general tendency among programmers is to immediately jump to a linear model for any parameter. The person submitting this question had normalized the angle to [0,∏/2], then had a series of if-statements to determine the parameter value.  Next, the parameter value was modified again based on the quadrant containing the actual angle. The question was whether or not a more compact approach was possible.

The answer depends on whether we can find a base function that has the necessary values at the prescribed data points and behaves in a ‘reasonable’ manner as the angle varies across its domain.  In this case, I looked as the cosine function as a starting point.  The absolute value of this function is 1 at Θ = 0 and decreases to 0 at Θ = ∏/2 and then increases back to 1 as Θ increases to ∏.  It does so in a manner that was similar to the sequence of linear approximations modeled by the if-then-else blocks from the person submitting the problem.

A base model in [0,∏] might look like αzmax|cos Θ| .  Fortunately, as Θ moves from ∏ to 3∏/2, the increase in f to zmax can be modeled like a reflection about the horizontal axis. So, we can create a relatively compact model by

1 – normalize the input angle into [0,2∏) – note the open interval at the end
2 – compute p = αzmax|cos Θ|
3 – for Θ in [0,∏], f(Θ) = p, otherwise f(Θ) = zmax – p

Of course, like any other model, this one needs to be tested to see if the parameter values are reasonable for values of Θ other than the ones used to fit the model.  Usually, this is based on some aesthetic criteria.  I hope the exercise shows how to think about such problems in a manner other than breaking the input into a small range, using linear interpolation inside that range, then modifying the value based on quadrant.

Categories: Flash, Math Tags: , , ,