Make a circle rotate around a point - java

Circle c1 = new Circle(20); //Initialize
c1.relocate(200, 200); //Set coordinates
I will say right off the bat that I do not understand trigonometry. From what I've been able to find online, I need to use cos and sin + an angle, but I do not understand how to make it happen.
How do I make the circle rotate around a specific point? I want to have a gap of 5-10 pixels between the rotation point and the circle's layout. So visually, the circle will be rotating around a blank space of 5-10 pixels.
Code snippets will be greatly appreciated, as well as tutorials.

Related

How to draw line path on top of arc using Canvas paint in Android

I am working in an android application where i need to draw a graph like this.
I have drawn the arc using paint and canvas but i didn't know how to draw the line path along with the text as mentioned in below picture!
Any heads up on this would be really helpful for me. Thanks in advance.
In order to keep direction of the line truly, you have to use many trigonometric functions and calculus. However, for such cases you can use canvas.rotate() for tricky solution. For the solution, first you calculate angle of line according to a value. For example, assume your arc represents total value of 200. The left side is 0 and the right side is 200, then you get the value of 80. With these values, you can calculate the angle like that 180degree * (80f)/(200 - 0) it gives 72 degree. Then you can rotate the canvas for drawing canvas.rotate(70f,centerX,centerY). CenterX and CenterY are values of the center point of the arc. After that, you can draw your line as you draw to line at the left-bottom corner of the canvas canvas.drawLine(0,100,20,100,paint).
canvas.save()
canvas.rotate(70f,centerX,centerY)
canvas.drawLine(0,100,20,100,paint)
canvas.restore()

Get radius from a circle to screen corners

I followed an online tutorial, I did not understand how the professor managed to get the distance of a circle from the top left corner of the screen:
//calculate the distance from epicenter (of a circle) to the top left corner of the screen
double theta = atan(epicenter.dy/epicenter.dx);
double distanceToCorner = epicenter.dy / sin(theta);
I would like to know how to get the distance from all the other screen corners (and possibly have an explanation of what has been done).
Thank you
Assuming, that in android you can get screen width and height, you can simply count the distance at horizontal and vertical axis separately.
Getting the distances at those axes, you can use Pythagoras equation, like
dist = sqrt( dx^2 * dy^2 )
To make it more felxible, just make a function, that takes corner position as a parameter and make the dx and dy as a absolute difference of corner and epicenter location.
Going back to your question and atan(...), I don't quite understand the need of using this here, except if that's a project for the math class :)
I know this is not the answer but if i understand what you mean, then this image might be helpful.

Drawing a filled Polygon with libgdx at the right position

I am currently implementing a lighting system to my game.
My light class calculates a polygon for my light to be visible in.
All I need to do now is to cut my light texture in this shape.
I am trying to archieve this by creating a polygonRegion and drawing it to a polygonSpriteBatch.
Thats what I do at the moment:
polygonRegion = new PolygonRegion(new TextureRegion(light), vertices,
new EarClippingTriangulator().computeTriangles(vertices).toArray());
and in the drawing step:
polygonSpriteBatch.setProjectionMatrix(lightHandler.tiledTest.cameraHandler.camera.combined);
polygonSpriteBatch.begin();
polygonSpriteBatch.draw(polygonRegion, 0, 0);
polygonSpriteBatch.end();
The polygon is actually working fine and as intended but problem is currently, that the actual light texture doesn´t seem to show up at my actual light´s coords in the center of the polygon, but on the lower left corner of the map. So my light polygon is actually black until I place it in that very corner.
Here is a screen with some light sources placed on the map. Please ignore the green and yellow lines. Those are for debugging the polygon.
https://1drv.ms/i/s!AgucvuUdePpwhZg7rqn6pk7cYktf1A
This is how i want my light polygon to actually look:
https://1drv.ms/i/s!AgucvuUdePpwhZg6Y8Y2JiKplGm6ig
I hope you can help me with this problem!
Apologies for any mistakes I did with this post.. it´s my first one here!

Calculating visible radius in Google Maps on Android

I'm trying to figure out how to calculate the largest radius of the screen's visible region.
(Before you say: Hey! Rectangulars don't have a radius! I understand that screen is rectangular (if camera is positioned in 90 degrees and not tilted), I'm talking about the radius of an imaginary circle that wraps the screen, or, the distance of the edge between the center of the screen to one of the corners of the rectangular, which is the same).
So, I understand that in a normal situation when screen is not tilted, I could take the distance between VisibleRegion.latLngbounds.southwest and the center of the screen to find the radius, but when screen is tilted, it becomes trapezoid.
Now, if the screen is an isosceled trapezoid, then I could take VisibleRegion.farLeft for example (which would be equal to farEast) and calculate the distance this way:
VisibleRegion vr = map.getProjection().getVisibleRegion();
Location center = new Location("center");
center.setLatitude(screenCenter.latitude);
center.setLongitude(screenCenter.longitude);
Location farVisiblePoint = new Location("farPoint");
farVisiblePoint.setLatitude(vr.farLeft.latitude);
farVisiblePoint.setLongitude(vr.farLeft.longitude);
float radius = center.distanceTo(farVisiblePoint);
My question is:
Is there any situation with the map that the calculation above will be wrong? Can the trapezoid not be an isosceled one?

Android inscribed circle

I am currently working on Code based drawables in Android but ran into a little bump, I have a rectangular LinearLayout that I want to set it's drawable to a circle I have reasons for doing this in code so please do not recommend xml, I did some searching on Google and was only really able to come up with the opposite an inscribed rectangle in circle and that is not what I need.
So let's say I have a rectangle of 80 wide and 120 in length(these are random guesses, and need to be able to change) what would be the formula I need to use to determine the largest circle I can create in this rectangle and when I say circle let me be more specific I do not want a oval I want a full circle.
So this question is simply what would be the proper formula needed for this. Thank you for your time =)
int Radius = Math.min( width, height ) / 2;
That is the largest radius circle that can fit in the rectangle
Well I'm back again and feel slightly stupid on this one,
The answer came to me during good old shower time (doesn't it always). I was thinking about my problem in the 3d senses something I regretfully did not do before I posted on here. It occurred to me that if I want to make a for lack of better term a perfect circle that the diameter of this circle would always be constricted by the smaller side of the rectangle and then you can account for that to center the circle.
So in my scenario my circle with be 80 in diameter because it would be restricted by the width of the rectangle. Sorry for wasting your time have a good day =)

Categories