Draw circle that passes over two points - android

I get too points A and B, and I want to draw an arc that passes over the two points (in other words, determinate the circle center coordinate C).
I know the radius, and angle, and the two points coordinates.
I hope I'm clear.
Could you help me ?
Thanks.

You know the distance from two points to the center of the circle (the radius).
Draw two circles with the same radii but with center of these two known points A and B. Where these two circles intersect is the center of the circle you are looking for.
I'm not sure what you mean by "I know the [..] angle"

Related

Click Listener on canvas arc

I want to draw arc on canvas with progress percentage on circle and need to perform click on both the color (blue and green).
How to make click listener for the same.
You have two circle for grean line
Two circle makes green area(difference of inner and outer circle) say circles G1(inner), G2(outer)
first find circles sector area of G1 and G2 say GS1 and GS2.
Now find touch point form on touch event say p1. If p1 lie in GS2 but not in GS1 than you have touched on green line
Similarly you have two circle for Blue line and you can find touch point
See this link also - Efficiently find points inside a circle sector

Close two arcs together

I'm designing a custom widget which have a gauge similar to this blue one :
(except this is a continuous gauge and not a splited one)
I tried to draw a path with two arcs :
private void drawGauge(Canvas canvas) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
float degreesToDraw = positionToDegree();
gaugePath.addArc(secondArcRect, 90, degreesToDraw);
gaugePath.addArc(faceRect, 90, degreesToDraw);
gaugePath.close();
canvas.drawPath(gaugePath, gaugePaint);
canvas.restore();
}
my two arcs are well drawn but the gaugePath.close() don't work as excepted since it close the path with the gauge start points (lower points). What I want is to draw a line between the two end points of the arcs(the higher points).
Unfortunately, I've no idea about how to find their coordinates to draw this wanted line.
FYI, I'm currently drawing this :
Any idea/help ? :)
The trouble was that faceRect and secondArcRect hadn't their center aligned on the y axis.
Simply fixing this and making them sharing the same y position for their bottom-right point(to have the two arcs cross themselves at the start and then fill properly) is enough

How to detect shape collision - Android

I would like to detect collisions between shapes dynamically drawn on a canvas (SurfaceView) for an Android game.
I can easily use intersect method of Rect or RectF objects but the result is not very good (see picture below where I have a "false" detection).
I don't want to use Bitmap so it's impossible to use the "pixel perfect" method.
Do you know a way to do this for circle, rect, triangle and other basic shapes intersection ?
Thx for help ;)
For a good collision detection you have to create your own models behind. In those models you specify the conditions that two objects colide.
For example, a circle is described by the center position and by the radius. A square is described by the left down corner and by the edge length.
You don' t have to describe all possible poligons, you can use the so called bounding boxes, meaning that, for a complex random poligon you can use a square or whathever shape fits it best(also you can use multiple shapes for a single object).
After you have the objects in mind you compute the condition that each one of them will colide with all other shapes including itself.
In your example The sphere and the square colides if the distance between any corner of the square is greater than the circle's radius.
Here you can read more http://devmag.org.za/2009/04/13/basic-collision-detection-in-2d-part-1/
This problem can get very complex, keep it simple if you want something simple.
Here is a directly applicable method I use in my own game to detect circle and rectangle intersection. It takes the ball (which is a view in this case) and the rectangle (also a view) to be checked for collision with the ball as parameters. You can put the method in a Timer and set the interval you want the circle and rectangle to be checked for collision.
Here is the method:
public boolean intersects(BallView ball, Rectangle rect) {
boolean intersects = false;
if (ball.getX() + ball.getR() >= rect.getTheLeft() &&
ball.getX() - ball.getR() <= rect.getTheRight() &&
ball.getY() + ball.getR() <= rect.getTheBottom() &&
ball.getY() - ball.getR() >= rect.getTheTop())
{
intersects = true;
}
return intersects;
}
getR() gets the circle's radius
getX() gets the center of the circle's X position value
getTheLeft() gets the rectangle's left X value
getTheRight() gets the rectangle's right X value
getTheTop() gets the rectangle's top Y value
getTheBottom() gets the rectangle's bottom Y value
If you can't directly use this method in your code you can still conjecture the logic it entails to implement it where it would work for you. It detects all collisions without using pseudo-collision detection like a collision box for the circle.
Good luck! And if you have any questions feel free to ask, I'm here to help!
To know if a polygon in 2d is colliding with a circle, you can test, for each of its lines, where is the point on the line that is closest to the center of the circle (this might help).
Then, check if the point you found is between to two corners that make the line - that is, that the point is actually on the line, and not just on its continuation - and if the distance of that point to the center of the circle is smaller or equal to the radius of the circle. If both are true for any of the lines of the polygon, you have a collusion. You also have to check for the edge cases where the corners of the polygon might be in, or touching the circle.
For two circles, this is easier. Check the distance between the centers, and compare it to the sum of their radiuses. If the distance is smaller or equal to the sum, you have a collusion.

find radius of freehand drawn circle using android onDraw()

i have to draw circle with free hand in onDraw() method.
After drawing the circle, i have to find the radius and center of that circle and show that circle again with drawCircle() method.
Can anyone help me to find the radius and center of circle with free hand drawing.
You could take the center as the average of all the points on the edge.
And the diameter as the largest distance between any two points.
Or once you have the center, find the distance between each edge point and the point across from it. Then average these.

android 2d arc collision detection

i have a rotated arc drawn using android 2d graphics
c.drawArc(new RectF(50, 50, 250, 250), 30, 270, true, paint);
the arc will rotate while the game is running ,
i wanna know how i can detect if any other game objects(rects ,circles) collide with it ??
this is the first time for me to write a game :)
i saw something like this in http://hakim.se/experiments/html5/core/01/
Thanks in advance
Arc collisions are slightly harder then normal collisions, but using boolean algebra you can easily check if a given point is inside your arc.
Take a look at the following picture.
There are 3 objects here. The black sphere, this visualizes your arc, if something collides with it, it might be inside your arc. The red sphere on top of the black sphere, this visualizes the 'inside' of the arc, if something is inside the red sphere, it's definately not 'inside' the arc. Now there is also the green triangle that Visualizes the 'cut-off' of your arc, anything inside the green triangle is also definately not in your arc.
Testing if something is inside the black sphere is easy. (object's distance to center of sphere <= radius of sphere). Same for the red sphere. The green triangle is a bit tricky, you first have to construct this. Find the start and end radians of your arc. and rotate a unit vector by start radians. Then rotate a unit vector by end radians. Lengthen both these vectors by 2 * the radius of the black sphere. Now use the center point of your arc and the positions of two vectors with added the center position as the 3 points of the triangle. You can then use one of the point-triangle collision solvers: http://www.bing.com/search?q=point+triangle+collision&go=&form=QBLH&scope=web
So remember: collision with arc = (collision with black sphere) && !(collision with red sphere) && !(collision with green triangle).

Categories

Resources