I want to create complex shapes like the intersection of two circles and a rectangle. After a little research, the java.awt.geom.Area class seems ideal for this task.
I was alarmed, however, when I discovered that the awt package awt not ship with the android SDK. Does anyone know of any alternatives for Android that allow me to create complex shapes by defining the union and intersection of simpler shapes?
awt
Note. Using cropping graphics to draw a figure does not work, because I do not just want to draw the shapes, but also want to save the shapes in memory to detect collisions and other interactions.
Android alternatives to java.awt.geom.Area
EDIT : @numan pointed out a great option using some classes in the Android SDK that I did not know about during the initial answer:
https://developer.android.com/reference/android/graphics/Region.html https://developer.android.com/reference/android/graphics/Region.Op.html
Region allows you to define geometric regions, and then you can use the Region op() method with Region.Op enum to calculate intersections and more complex shapes.
Region
op()
Region.Op
enum
You can use Canvas to draw custom shapes, especially using clip methods *:
Canvas
http://developer.android.com/reference/android/graphics/Canvas.html
Here are some pages about 2D graphics in Android:
http://developer.android.com/guide/topics/graphics/2d-graphics.html http://developer.android.com/guide/topics/graphics/2d-graphics.html#shape-drawable http: // developer.android.com/guide/topics/graphics/opengl.html
Some other good options if your graphics remain the same (or roughly the same) are based on XML:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#drawables-from-xml
And one solution that I find pretty neat is using 9-patch drawables:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
Collision Detection This may be redundant for your purposes, but there are a number of physics libraries for the game:
http://www.andengine.org http://code.google.com/p/andengineexamples/
http://bulletphysics.org
http://www.emini.at/
http://www.dremsus.com/index.php/2012/01/box2d-game-demo-in-android/
Android OS, libgdx and box2d
Or you can roll your decision:
http://cooers.blogspot.com/2012/08/simple-collision-detection-in-2d.html
http://content.gpwiki.org/index.php/Polygon_Collision
http://www.codeproject.com/Questions/244344/Collision-Detection-in-Android
Collision detection for rotated bitmaps on Android
It really depends on the goal; for games, you will probably be best off using the library; but if collision detection is the only function you need, you better do it yourself to save resources.
Extra Credits: Some Android Library Indexes
http://www.appbrain.com/stats/libraries/dev
http://www.theultimateandroidlibrary.com/
http://www.openintents.org/en/
Android UI takelit uses Skia to render graphics, and skia uses Region abstractions for specified operations on shapes (for example, intersection, union, subtraction. See Region.Op section) of shapes from paths or rivers.
The Region class also helps you get simple conflict detection using the Region.quickContains or Region.quickReject methods.