Posts Tagged 'geometry'



Amazing Maps (and one in particular :)

Today I came across (and followed) Amazing Maps twitter account. They post loads of interesting maps, like the one that shows who has supplies the oil, or the one that shows that my country has world’s best extinction rate. This post, however, is dedicated to the map of countries prosecuting gays:

Personally, I don’t care if you are gay or not (unless you’re girl that I am interested in), but this map scored two points on my bullshitometer for dirty tricks it uses to influence my opinion. 1st, and obvious, was to cover offending countries in blood. Of executed gays, I suppose. 2nd, and less obvious, is clever choice of projection where gay-neutral Greenland (small island with 80% of its area being nothing but ice) has roughly the same size as whole gay-hating Africa. So, I decided to re-do this map using positive green color and population-based projection to make it a bit more representative:

Turns out it does not look that different, after all :) Gay-neutral China, the world’s most populated country, conveniently offsets all those aftrican gay haters. In fact, I’m sure that very soon indian government will sort out their bureaucratic bullshit, and half of this green spot will be gone.

Update: they have now posted new version of the map that uses better projection and breaks it up by punishment severity.

[ᴘᴏʟʟ] Left or right?

What is better way to fill Mandelbrot exterior? Colors were intentionally left dull, please vote for best geometry:

left or right?

In case you want to check more locations, click here.

Gyroscope adventure

In case you can’t fully understand yet what Adobe means by focusing on (desktop) gaming and video and not general purpose apps, allow me to demonstrate. Suppose you are making mobile app and for whatever reason you want to track device orientation. How hard can that be? Check it out:

Apple way

If you’re native iOS app developer, you are dealing with ecosystem that does support general purpose apps. You have simple CMDeviceMotion class that performs sensor data fusion, filtering, bias removal, etc, and gives you orientation data in any form you want (roll + pitch + yaw, or matrix, or quaternion). Case closed. The same class conveniently splits accelerometer data into gravity and user applied acceleration, btw. In a word, it’s perfect.

Adobe way

If you’re AIR app developer, prepare yourself – you’re going on the adventure. You can start by looking at flash.sensors package – for some mysterious reason, it has accelerometer API for desktop, but no gyroscope API for mobile. Why? Because Adobe does not feel obliged to include every piece of code you might think of in their runtime. But don’t give up your hope yet – Adobe has the solution for this kind of problems – AIR native extensions. And, it turns out that Adobe made one for you to access gyroscope data. Despite of being abandoned in 2011, apparently just before Adobe’s focus shift kicked in, this ANE still works with current AIR 3.x.

Okay, this is the part where you’re happy that you don’t have to write ANE yourself, and it seems that getting your hands on device orientation data is now only a matter of few additional build settings. Well…

This extension API, designed to be Accelerometer class twin, has two major problems in the way. Number one is that it only exposes raw gyroscope data, i.e. rotation rate. Since this is not something that flash developers do every day, you probably have no idea how to go from radians per second to orientation quaternion, or transformation matrix. So to use this ANE, you will have to learn some new tricks, such as finding approximate differential equation solutions, Taylor expansion of matrix functions, series summation and evaluating indeterminate forms. If you are still with me, good guy Oliver J. Woodman will guide you through this hell (pages 21 to 23).

Ok, now you’re done reading that and ready for action, right? Not so fast – there is problem number two. Let me just quote this comment from ANE source code:

// The singleton ExtensionContext object listens for StatusEvent events that
// the native implementation dispatches. These events contain the device’s
// gyroscope x,y,z data.
//
// However, each Gyroscope instance has its own interval timer. When the timer
// expires, the Gyroscope instance dispatches a GyroscopeEvent that contains
// the current x,y,z data.

Thank you, Adobe engineer, for this brilliant idea. Because there just can’t be enough lag or noise in my data. Sigh… so what do you do about this? You bypass ANE AS3 wrapper, and access its internal methods over low level interface. Of course, this means that you have to study both wrapper and native code beforehand :(

And here, my friend, we come to the end of our wonderful journey. I will go back to work on my AIR app, and you will maybe go and write your own ANE, with blackjack and hookers. Or you may choose to continue where I left off – maybe add Kalman filter or something. And don’t forget to write back, if you do :)

Picking random points in elliptic arc or sector

This was the result of random flashkit thread encounter and has no much real life value, probably. The closest thing I found to what that guy was asking for was this 2009 post explaining the trick to pick random point in the circle, but it is remarkably easy to extend it to the ellipse, or even arbitrary elliptic arc or sector. It is interesting in that you pick correct point on 1st try versus, for example, 4/π ≈ 1.27-th try if you simply select random point in ellipse bounding box and reject outliers – and some extra Math.xxx calls pay for that.

How to draw numbered billiard balls

This blog desperately needs more posts, but I hardly have any subjects to write at length about. And this is where wonderfl comes to the rescue – some of those codes are so complicated that one could give two hours talk about them. This code is that kind of code, and tonight I am going to explain just one small part of it – drawing numbered billiard balls. Continue reading ‘How to draw numbered billiard balls’


Old stuff

July 2020
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Oh, btw…