PHP ellipses

This may be upside down. $ellipseFactor=$majorSemiAxis/$radius;
 
PROBLEM SOLVED!!!

An hour or two after my last post, I went back to Wikipedia, and found the missing element. I went to reply, but the forum was closed.

While it says that you CAN cycle an angle (from 0 to 2PI radians) and then apply the formulas I was using to create an ellipse:
ellipseBorderPixel_X = Xradius * cos(angle)
ellipseBorderPixel_Y = Yradius * sin(angle)

it says that angle IS NOT the angle that the pixel lies on!

It then goes on to give equations that relate the two different angles...

To get to the essence, we must factor in the height/width ratio, or more specifically the, the Xradius/Yradius ratio.

So we change the test program to:
$beta=atan(($y/80)*(2/3));

And all the red lines line up with the yellow!

testellipse3.png


So in the main program we add a new variable to the mix (before the loop, so the calculation is only done once):
$hwFactor=$Xradius/$Yradius;

Then in the loop we change the angle calculation to:
$angle=atan( (abs($center['y']-$row) / abs($center['x']-$column)) * $hwFactor );

And we get ellipses! Yeeeoooooooo!

realEllipse.png


I've been working on the overall code, fixing bugs in the HTML input form's JavaScript (seems bug free now, I'll try to post it soon), and testing and re-writing the background image handler code (works now) and adding foreground image capability (very soon).

From there I'll be writing a routine/formula that makes a star pattern by:
calculating the real angle (0 to 2PI, not just the one transcribed into the (+,+) quadrant as I do now) (if it's stretched, I'll use the ellipse angle formula)
dividing the angle value by the number of points.
subtracting a linear percentage value from the radius of the circle/ellipse that encloses the star based on the angle.

Seems like it will work...

In the mean time, with the tinkering around I did playing with the ellipse formula, I found I could create many shapes, many odd, many quite interesting....

By creating two new user-defined variables:
$swell
$leaf
we can modify the formulas:
$hwFactor=($Xradius/$Yradius) * $swell;

$angle=$leaf * atan( (abs($center['y']-$row) / abs($center['x']-$column)) * $hwFactor );

If we set $swell to equal $Yradius/$Xradius (the inverse of $hwFactor) then we get the two intersecting circles we had before. By adjusting it, we can control the "swell factor".
If we set $leaf to 2, the "swollen" ends are split in two, and we get a four leaf clover!

fourLeafClover.png


And other patterns are possible, too! Here's one for which I forgot the formula, but it's similar to what I've been doing.

newRainbow6115.png


And one with a background, and transparent gradients...

newRainbowFrog.png


From here, who knows what my imagination will lead to. And kids, yours is just as powerful! Do your homework, and see that math can be fun, even in real life applications! And don't forget to brush your teeth!

Again, Peace, ya'll!
 
In other words, I was right in my very first comments, but for reasons of which I was totally unaware.

"1) Are you SURE horizontal pixels measurement is the same as vertical pixel measurement?"
 
tkhunny said:
In other words, I was right in my very first comments, but for reasons of which I was totally unaware.

"1) Are you SURE horizontal pixels measurement is the same as vertical pixel measurement?"

Perhaps after 3 pints of Guinness Extra Stout. And it also depends on how hunny you are. :D :D :D
 
Let us all remember that theta in a parametric definition may not mean the same as theta, some reference angle.

Excellent hardiness getting all the way through that.
 
As promised, I finally have a working version stable enough to post for public use.

If you want to make your own rainbows of color/transparency gradients, see this page:
(you don't need to download any software or run anything on your computer, just use the browser you're using now)

http://owl-eye.org/rainbow-maker/

It's as easy as point and click to choose the anchor colors that the gradients are made from.
Type in a few values for height/width and gradient span (the number of colors, i.e. pixels, between anchor colors), choose a foreground and background file if desired, and whah-lah!!!!

You can see the fully working PHP code highlighted in full color to make it easy to read,
and download the complete package if you like, at:

http://owl-eye.org/rainbow-maker/code/

I had some REALLY incredible designs that came from using this, but alas, I accidentally deleted them. Sigh. :(

But I made one new one. It only begins to hint at what is possible...

newRainbow8222.png


I'll be adding more features to this as time goes on, so if you get the code, check back if you like for updates...

Aloha!!!
 
Top