I need to calculate the intersection between two shapes in flash / action script.
The problem is I can't access the shape's nodes and segments, and their coordinates, so there's no way I can calculate this.
Do you know a way?
edit: further explanation:
I imported irregular polygons from an EPS file to a movieclip with shapes in it.
The mathematical solution to the problem is trivial, but to do that, I need to access by AS code to the coordinates of the nodes that make up the polygons, which I tried with no success.
That is what I'm trying to accomplish.
edit2: dismiss this question.
It's not possible. The workaround I'm applying is to save the polygons in SVG and parse them to get a list of nodes. then will feed that list to flash to calculate the intersection and areas on runtime.
AFAIK, there's no way of retrieving the data for any given shape in flash. It's something internal unfortunately. However, you should still be able to calculate a sufficient approximation of the area between your two shapes by using a Pixel Bender kernel. Using a ShaderJob, you can run the calculation asynchronously and thus not locking the UI.
The idea goes something like:
- Capture bitmap of the first shape
- Capture bitmap of the second shape
- Create ShaderJob using your Pixel Bender kernel, using the two bitmaps as inputs. For each pixel, the kernel will calculate wether the shapes intersect or not, and possibly by how much. Use one of the output channels for the result of the calculation.
- Take the resulting output and sum it all up for a final alpha value.
I'm not sure if this is less of a hassle to you than using your SVG approach, but it's an alternative at least. It might make sense to calculate the intersection of the two shape's bounds and only capture a bitmap of the intersecting rectangles in the shapes. It is an extra step, but at the very least it's likely more memory efficient, possibly more efficient in terms of cpu time as well.
I'll be fascinated if there is an answer, but as far as I know the Shape class of AS3 is pretty sparse.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Shape.html
Annoyingly, the equivalent JSFL class is full of goodies for exactly what you want. I don't suppose that would be of any use to you?
http://livedocs.adobe.com/flash/9.0/main/00004384.html#wp119221