2
$\begingroup$

In the attached image are three functions. The first is a displacement function which takes angle $t$, and returns a radius. The third one is a semicircle and the second one is a semicircle with the displacement function $d()$ applied.

Note that the second function includes $y$ in the right hand side (inside $\text{atan2}$). I need to factor this equation so that it is entirely dependent on $x$, and there is no $y$ variable on the right hand side of the equation.

Reproduced here, the equation is:

$y=\sqrt{ d(\text{atan2}( y, x ) )^2 - x^2 }$

I need to get this ^ y moved to the left.

graph

edit: bigger picture, I'm trying to do raycasting of a sphere with a displacement map using an orthographic camera. This is why I only care about the greatest y, because lower y are not visible to the camera due to occlusion. My thought was that if I could scan across with a single x, on a 2 dimension version of the problem I'd be closer to solving the 3 dimensional version.

edit: let me ask this a different way. Given a line, how can I find the location of a the points which this line intersects with the equation?

edit again: it seems the answer is binary search. http://http.developer.nvidia.com/GPUGems3/gpugems3_ch21.html

  • 0
    thank you for your reply. What I would like is, where there are multiple y, I want the greatest, or maximum y. Is that possible?2012-02-13

1 Answers 1

4

As Rahul has already commented, you can't solve this for $y$ because $y$ is not a single-valued function of $x$. I also doubt that you can express the greatest $y$ for a given $x$ in closed form.

In polar coordinates, your equation is just $r(\phi)=d(\phi)$, and this allows you to write both $x$ and $y$ as functions of the single parameter $\phi$:

$ x=r\cos\phi=d(\phi)\cos\phi\;,\\ y=r\sin\phi=d(\phi)\sin\phi\;. $

Now you could express $y$ as a function of $x$ if you could solve the first of these equations for $x$. With $d(\phi)=1+\sin(20\phi)/5$, this is $x=(1+\sin(20\phi)/5)\cos\phi$. You could express $\sin(20\phi)$ in terms of $\sin\phi$ and $\cos\phi$, but that would lead to a high-order polynomial in $\sin\phi$ and $\cos\phi$ whose roots are unlikely to have a closed form.

Often people post questions about parts of their problems, which turn out to be unsolvable because they've gone down a dead end with their bigger problem. If you tell us why you want to do this, we might be able to help you more, e.g. by suggesting how to do it in polar coordinates instead.

[Edit in response to the edit in the question:]

You could consider scanning through values of $\phi$ instead. Since

$\dot x=\dot d\cos\phi-d\sin\phi=4\cos(20\phi)\cos\phi-(1+\sin(20\phi)/5)\sin\phi$

(where the dot signifies differentiation with respect to $\phi$), you have $\Delta x\lt\sqrt{4^2+1.2^2}\Delta\phi\approx4\Delta\phi$, so with $\phi\in[0,\pi]$ instead of $x\in[-1.2,1.2]$ you'd only need about five times as many steps to get the same density of $x$ values everywhere.

  • 0
    it's also occured to me that I *could* do a search of ϕ instead. I've already got the function I need to pinpoint the point on a surface of a sphere from the picture plane. I can get ϕ from that, and search surrounding coordinates in the displaced function until the displaced surface projects onto the pixel I'm testing.2012-02-14