1

Forgive me as I am a programmer, not a mathematician.

I have a rectangular plane that I am drawing shapes onto, I want to create an effect where coloured shapes traveling to the outer edges of this rectangle become more and more faded in an oblong pattern where the sides of the rectangle are a tangent to the furthest points of the oblong in its respective X/Y directions, when the points are outside the bounds of the oblong they will be completely invisible, when they are dead in the center they will be 100% visible, when they are half way between the boundary of the oblong and the center they will be at 50% transparency. To achieve this I initially calculated the distance of the point to the center of the rectangle and divided that by the width of the rectangle to get a ratio of how far from the center of the rectangle my point is relative to the width, and use the output as the opacity for the shapes I draw at the points. This approach obviously only works in perfect circles and when the rectangles width is less than its height.

The solution I can think of is some equation where it creates a elongated hemisphere that's max Z value is 1, and its center (peak?) = the center of the rectangle and its sides are elongated to meet the edges of the rectangle & it should then return a Z coordinate for any given X/Y coordinate within my rectangular plane, which should be a figure between 0-1 I can use for the opacity, if my idea is at all plausible.

I did some looking into it and someone had explained this, a sphere with center (x0, y0, z0) and radius r is the locus of all points (x, y, z) such that (x - x0 )^2 + (y - y0 )^2 + ( z - z0 )^2 = r^2 which seems to almost fit what I am looking for, but i do not know how to manipulate the sphere to elongate its sides to match the width/height of my rectangle. As i said, I am a programmer not a mathematician and all of this is baseless theory I have pulled out of thin air whilst trying to solve my problem, apologies if my terminology is a world off and my ideas are half baked at best, any help and/or direction would be appreciated.

James T
  • 133
  • It is a little difficult to read that and interpret what you are asking. Can you boil your question down to sentence or two? Try to cut out the design information and focus on the mathematical question. I suspect that's why you have no answers yet.

    The question in the title is answered by the formula you gave, if you want the $z$ coordinate on the hemisphere for any $x$ and $y$ point you simply substitute $x$ and $y$ into $(x - x_0 )^2 + (y - y_0 )^2 + ( z - z_0 )^2 = r^2$ and solve for $z$.

    – Bennett Gardiner May 19 '15 at 13:00
  • Sorry, I didn't know how to word it so I've probably way over-explained it and made it difficult. The main issue i have with that equation is that i do not want a perfect sphere, I want to be able to manipulate the height/width to match a rectangles height/width so the sphere would come out looking squashed? is that a better way of putting it? – James T May 19 '15 at 13:13
  • Since I'm failing putting it into words I've attempted to explain it visually, basically, can i manipulate the first equation to fit the second scenario? http://i.imgur.com/JI1qtgE.png – James T May 19 '15 at 13:21
  • 1
    Ohhh. That's much better. You want an ellipsoid. Basically the same equation but with a stretched axis,

    $$\frac{(x-x_0)^2}{a^2}+\frac{(y-y_0)^2}{b^2}+\frac{(z-z_0)^2}{c^2} =1$$

    – Bennett Gardiner May 20 '15 at 05:28
  • 1
    For your example, if you only want the $x$ axis stretched, then $a=37.5$, $b=c=12.5$.

    $(x_0,y_0,z_0)$ is the location of the centre. Make sense?

    – Bennett Gardiner May 20 '15 at 05:33
  • 1
    Yes, perfect. I tried some stuff on wolfram to graph it and got very close to this but this should work perfectly, thank you. – James T May 20 '15 at 08:42

0 Answers0