Picotope

I have been keeping a saltwater aquarium for over a year now. This September I upgraded my little 5 gallon experiment in the hobby that I had been running for a year to a 24 gallon all in one system. This new system gave me a lot of freedom because of the very high quality and powerful light. Also it gave me much more space that I had previously.

 

My 24 gallon AquaPod

My 24 gallon AquaPod

After several months and several dollars I’ve managed to get the AquaPod quite full.

 

 

My AquaPod after a few months.

My AquaPod after a few months.

 This aquarium sits in my living room so I decided to set one up on my desk. Desk space is limited so I went with a very small 3 gallon picotope by JBJ. 

 

Empty Picotope on my desk.

Empty Picotope on my desk.

The light that was included in the Picotope was a crappy little 9W powercompact florescent so I upgraded it to duel 18W power compacts for a total of 36W. I also added a hang on back filter that was intended for 70 gallon tanks, overkill but for a reason. The filter is big enough that I can fit equipment in there like the heater and the thermometer, keeping it out of the already small display tank. You can see in the above picture that I painted the back of the tank black, this is so the filter and cords aren’t visible. 

 

Rocked tank with 1 coral.

Rocked tank with 1 coral.

 

 

I added a little bit of rock. This acts as a natural filtration device and makes it look like a reef. The photo above is also showing one coral, a frogspawn (Euphyllia divisa). 

 

Aquatic Zen Garden

Aquatic Zen Garden

 

 

Overall it makes a very nice addition to my desk. Hopefully it will lighten up the winter months to come. If your interested in the hobby and want advice please just give me a shout, love to help you out.

The Point Inside a Polygon Problem

When I was writing Paddle Ball, I came to a point where I needed to determine wether the ball had actually landed on the paddle or not. The original version that was demoed at iPhoneDevCamp used an oval approximation that worked for the demo but was not accurate enough for final product. Before I could make an accurate determination of whether the ball was on the paddle I needed a detailed parameterization of the paddle itself. 

To get an accurate measure of the vertices of the paddle I exploited the accuracy of the iPhone’s multi-touch display by simply logging the x and y coordinates of my finger as I traced out a path along the paddle. I then took the log file and created a static float array of the points. This gave a very accurate path that outlined the shape of the paddle.

After several days of thinking on this problem and asking my math type friends I consulted the great oracle, google. There I found an elegant and efficient solution to my problem. In laymen’s terms, simply draw a line from the query point out to a large distance and count the number of times the line crosses the vertices of the shape. If the number is even, the point is outside, if odd, the point lies inside the shape. The beauty of this method is that it doesn’t require the shape to have any sort of structure (works for a paddle shape).

Below is the code that I used to determine whether the query point p was on the paddle or not. points is the static array of floats that make up the outline of the paddle. The direction of the ray out of the point is arbitrary, so the x-axis works just fine.


int counter = 0;
int i;
double xinters;
CGPoint p1,p2,p;

// In the case of paddle ball the query point will be the location of the ball
p = CGPointMake(theBall.location_x,theBall.location_y);

p1 = points[0];
for (i=1; i <= kNumPaddlePoints; i++) {
        // p1 and p2 make two consecutive points
	p2 = points[i % kNumPaddlePoints];

	if (p.y > MIN(p1.y,p2.y) &&
            p.y <= MAX(p1.y,p2.y) &&
            p.x <= MAX(p1.x,p2.x) &&
            p1.y != p2.y)
        {
		xinters = (p.y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y) + p1.x;
		if (p1.x == p2.x || p.x <= xinters) {
                        // If the ray crosses vertice, count it
			counter++;
		}
        }
	p1 = p2;
}

// If it crosses a vertice an even number of times it is outside the shape else inside
if (counter % 2 == 0)
	return NO;
else
	return YES;

From this I can determine if the ball collided with the paddle and will bounce or it missed and the game is over.

iPhoneDevCamp 2

 

Wanted to write a quick post to summarize my experience at iPhoneDevCamp 2 this past weekend in San Francisco.

I met a lot of great people and (for the most part) everyone was really nice, positive, and helpful. I spent a good deal of time with my competitors over at PinchMedia, who, despite being our competitors, seem to be some really nice guys. Makes it hard to want to compete against them (kind of).

The camp was particularly enjoyable for me because I got to put the AppLoop code aside for a few hours and work on something completely unrelated. For the hackathon I decided to make a simple game the emulated the beloved motion of bouncing a ping pong ball on a paddle. Turned out that this project was just the right caliber to bust out in a 24 hour period. 

Paddle Ball, as it became named, took honorable mention in the games category, earning me a year of web hosting, which is how you are reading this.

Thanks to the organizers for putting together a spectacular event, more food and beer than I knew what to do with and so much swag I could barely get it all onto the train.

Overall great time, look forward to coming back next year!