Android: looking for a drawArc() method with inner & outer radius

You can do this: Paint paint = new Paint(); final RectF rect = new RectF(); //Example values rect.set(mWidth/2- mRadius, mHeight/2 – mRadius, mWidth/2 + mRadius, mHeight/2 + mRadius); paint.setColor(Color.GREEN); paint.setStrokeWidth(20); paint.setAntiAlias(true); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStyle(Paint.Style.STROKE); canvas.drawArc(rect, -90, 360, false, paint); The key is in paint.setStyle(Paint.Style.STROKE);, it crops the arc’s center with the stroke that you define in … Read more

How to test if a line segment intersects an axis-aligned rectange in 2D?

The original poster wanted to DETECT an intersection between a line segment and a polygon. There was no need to LOCATE the intersection, if there is one. If that’s how you meant it, you can do less work than Liang-Barsky or Cohen-Sutherland: Let the segment endpoints be p1=(x1 y1) and p2=(x2 y2). Let the rectangle’s … Read more

Perpendicular on a line from a given point

I solved the equations for you: k = ((y2-y1) * (x3-x1) – (x2-x1) * (y3-y1)) / ((y2-y1)^2 + (x2-x1)^2) x4 = x3 – k * (y2-y1) y4 = y3 + k * (x2-x1) Where ^2 means squared

Changing the Coordinate System in LibGDX (Java)

If you use a Camera (which you should) changing the coordinate system is pretty simple: camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); If you use TextureRegions and/or a TextureAtlas, all you need to do in addition to that is call region.flip(false, true). The reasons we use y-up by default (which you can easily change as … Read more

Calculating a 2D Vector’s Cross Product

Implementation 1 returns the magnitude of the vector that would result from a regular 3D cross product of the input vectors, taking their Z values implicitly as 0 (i.e. treating the 2D space as a plane in the 3D space). The 3D cross product will be perpendicular to that plane, and thus have 0 X … Read more

2d game : fire at a moving target by predicting intersection of projectile and unit

I wrote an aiming subroutine for xtank a while back. I’ll try to lay out how I did it. Disclaimer: I may have made one or more silly mistakes anywhere in here; I’m just trying to reconstruct the reasoning with my rusty math skills. However, I’ll cut to the chase first, since this is a … Read more

Declare an empty two-dimensional array in Javascript?

You can just declare a regular array like so: var arry = []; Then when you have a pair of values to add to the array, all you need to do is: arry.push([value_1, value2]); And yes, the first time you call arry.push, the pair of values will be placed at index 0. From the nodejs … Read more

Java 2d rotation in direction mouse point

Using the Graphics2D rotation method is indeed the easiest way. Here’s a simple implementation: int centerX = width / 2; int centerY = height / 2; double angle = Math.atan2(centerY – mouseY, centerX – mouseX) – Math.PI / 2; ((Graphics2D)g).rotate(angle, centerX, centerY); g.fillRect(…); // draw your rectangle If you want to remove the rotation when … Read more

Javascript 2d array indexOf

You cannot use indexOf to do complicated arrays (unless you serialize it making everything each coordinate into strings), you will need to use a for loop (or while) to search for that coordinate in that array assuming you know the format of the array (in this case it is 2d). var arr = [[2,3],[5,8],[1,1],[0,9],[5,7]]; var … Read more

How do I reverse-project 2D points into 3D?

[*] Alright, I came here looking for an answer and didn’t find something simple and straightforward, so I went ahead and did the dumb but effective (and relatively simple) thing: Monte Carlo optimisation. Very simply put, the algorithm is as follows: Randomly perturb your projection matrix until it projects your known 3D coordinates to your … Read more

Categories 3d