Tag Info

Hot answers tagged

13

Golden rule when working with any kind of angle: Make sure you are using the correct unit. In this case, you should be using radians, not degrees. Math.sin(i * interval * Math.PI / 180); Math.cos(i * interval * Math.PI / 180); If you want to fire bullets directly between boss and player, use atan2, FYI.


10

Let's assume the large circle has centre A and radius R and the small circle has centre B and radius r moving towards location C. There is an elegant way to solve this problem, using Minkovski sums (subtractions, actually): replace the disc of radius R with a disc of radius R-r, and the disc of radius r with a disc of radius 0, ie. a simple point located at ...


9

What you want to do can also be thought of as reflecting the particle's velocity off the plane tangent to the circle at the point of contact. If you know the equation for doing that, then all you need to know is the circle's normal at the point of contact. To get that, all you need to do is normalize the vector from the center of the circle to the point in ...


7

The fragment shader is executed for each fragment with a single uv for this fragment which will probably never fall perfectly on 1. You could map the target area roughly to the width of a render target fragment. Eg something like: abs(hyp - 1) * CircleRadiusInPixel < BorderWidthInPixel*0.5 Further explanation: Your gpu rasterizes the triangles and ...


6

You are doing the division the wrong way round, and you are using degrees rather than radians, like the maths functions do. By chance this results in a pattern that look a bit like the desired. Just fix your calculation of the interval variable. var interval : Number = 2 * Math.PI / BULLETS_PER_WAVE; Edit: For those not familiar with the concept this code ...


6

With polygon-based graphics, the only option you have to better approximate a circle is to subdivide further. 720 triangles will result in a smoother circle, but 1440 will give you an even smoother circle, but 2880... A perfect circle, created using polygons, would require an infinite amount of infinitesimally small polygon sections (in other words, it just ...


5

I think the way that makes more sense is to have each circle move back half of the depth, instead of moving only one of the circles. That should be as easy as adding half of the penetration depth to each circle but in opposite directions: circlePositions[i] -= depth / 2f; circlePositions[j] += depth / 2f; But that's assuming you're calculating the ...


5

I think you should do 360 / BULLETS_PER_WAVE instead which gives in your case 360 / 72 = 5 degrees between each bullet. Also are you sure that the Math.sin and Math.cos functions wants their input in degrees and not radians?


4

The problem here is that sqrt(a*a + b*b) is non behaving in the way you expected it is non-linear as you can clearly see here: I don't see any immidiate way on how to fix this. (To be honest I'm surprised this worked in the first place). But I can give you the standard algorithm to accomplish this. This will also keep speed constant and you can use the ...


4

While you have been answered, here is a funnier answer : learn from nature. Use the golden ratio instead. const GOLDEN_RATIO : Number = 1.618033989; var interval : Number = 2 * Math.PI * GOLDEN_RATIO; See : http://www.mathsisfun.com/numbers/nature-golden-ratio-fibonacci.html


4

If you want to do vector graphics with OpenGL, you should do taht in shaders. E.g. gl_FragColor = ( length(gl_FragCoord.xy) < 0.5 ) ? vec4(1,1,1,1) : vec4(0,0,0,1); You can do some "supersampling" to make it smooth, or analytically compute the area of pixel, which is overlapped by circle. BTW. there is also OpenVG API out there.


4

Say the big circle is circle A and the small circle is circle B. Check to see if B is inside A: distance = sqrt((B.x - A.x)^2 + (B.y - A.y)^2)) if(distance > A.Radius + B.Radius) { // B is outside A } If in frame n-1 B was inside A and in frame n B is outside A and the time between frames wasn't too big (aka B wasn't moving too fast) we can ...


3

I will assume that A and B are the centers of the respective circles. First, we have two circles that move by some given velocities. When you update the position of the circles at the beginning of a new frame, their position will change by Velocity * diff, where diff is the time passed from last frame. If the collision engine finds that these two circles ...


3

The math is a bit easier if we center our coordinate system on the final position of the red circle, which I'll call p2 here. We can treat the red circle as stationary, given OP's comment above. So we're looking for a time t when the blue circle's position is exactly r1 + r2 away from the red circle at p2. We can find the position once we know this time. ...


3

I can think of a couple ways to approach this problem. (Figure 1) Find the closer tangent point to aim towards, then steer along the edge of the circle. This should be the path with the shortest distance. (Figure 2) In polar coordinates, plot a path that interpolates the angle Θ and radius r from the starting point to the desired point. These points are ...


3

Apart from possible degree/radian issue, I reckon the main problem is that you're using integer values for the calculations. You haven't shown GameConstants.BULLET_NORMAL_SPEED_X or its Y counterpart but make sure they are represented as floating point numbers, not integers. Alternatively, cast them into floating point values during the multiplication for ...


3

I assume that A and B are the centers of the two spheres: Sa, Sb. V = A - B is the vector that moves the center of Sa to the center of Sb: you see that A + V = B. ||A - B|| is the magnitude of V or modulus or length - as you prefere - that is the distance of the two spheres: p is how much the spheres are too close to each other. N = V / ||A - B|| is a ...


3

I can't imagine how your code would produce the image you linked. I could however, imagine how it might produce an image like this: With flat sides. So really what you want to do is increase the number of sides. Try setting: private int points=40; to something larger like private int points=360; If you wanted a loop like your image instead of a ...


3

I believe there's a bug in your code in this line: double rad=(i*360/points*3)*(3.14/180); ... which would cause the kind of error you described. I think the line should look like this instead: double rad=(i*360/(points*3))*(3.14/180); Note the parentheses () around points*3 If you fix your code, I believe your output will no longer be 'squiggly'.


3

Let b be the angle between vectors p1p2 and p1p3. Its value can be computed as: b = pi - atan2(p1p3.y, p1p3.x) The angle between p1p4 and p1p3 is b-a. Since p1p3p4 is a right-angled triangle, we know that cos(b-a) is the distance p1p4 divided by the distance p1p3. The answer is then: a = pi - atan2(p1p3.y, p1p3.x) - acos(r / length(p1p3)) Replacing ...


3

A quick google search shows this to be a common problem with line strips. I strongly suspect the correct answer is: don't use line strips. Use triangles instead, and build your own geometry so that it doesn't have gaps. Moreover, according to this answer on StackOverflow, it sounds like line rendering is not rigidly specified by the OpenGL spec the way ...


2

That's called a Boolean operation. You can find a video tutorial here for almost the exact situation you're asking about. Essentially, it looks like you create a new object with your two objects selected. You'll likely need to make your circle a cylinder first. The new object is a Compound Object of type Boolean. Then in the operations you select A-B (where ...


2

It sounds like your desired motion consists of two stages: first move directly toward the target point (x) until you hit the circle; then, move around the circle to the target point, if necessary. Since there are two stages, you could use a state machine with two states indicating which kind of motion you're currently doing. In the first state, just set ...


2

This is just using regular old sine and cosine to step around the circumference of a circle and place points. You just need to know the center of the circle, the radius and how many points you want. The following pseudo code will output a set of points that make up the positions of dots you need to make a circle of points: circleXY(Vector3f center, float ...


2

This isn't a problem with line strips. OpenGL is doing exactly what you have asked it to do: draw a bunch of rectangles oriented to match the 'lines' you've provided, each with a particular width which you've also provided. The problem is that you're imagining that OpenGL is going to magically join up the corners of those rectangles into a single swooping ...


1

Let's assume you want a circular arc from point A to point B, guided by control handle H which is the intersection of the tangents at A & B (and thus equidistant from A & B). Circles being the bread & butter of geometry, there are a hundred ways to skin this cat - but here's one... If we define: midpoint = (A + B)/2; perpendicular = (-(B - ...


1

Here is a Method that I use for circle vs circle collision : public static bool CirclesIntersect(Circle c1, Circle c2, out float depth) { float distance = (c1.Position - c2.Position).Length(); float sumOfRadii = c1.Radius + c2.Radius; depth = sumOfRadii - distance; if (depth < 0) { return false; ...


1

I looked at what I think is the AS3Math lib you're talking about. Here is their amCircle2d class. It doesn't look terribly useful, since it inherits from (amCurve2d)[https://code.google.com/p/as3math/source/browse/trunk/src/As3Math/geo2d/amCurve2d.as] but doesn't implement getPointAtDist, which, if you fed it a distance a long the circumference of the ...


1

Just did this using SDL but the theory is the same. Make your circle orbit your square by the distance from the center of the square to the corner plus the radius of your circle. Then limit the distance your circle can be from your square. Minimum would be -half square width -circle radius, maximum would be +half square width +circle radius. Here's the ...


1

I wanted to comment on the answer given by @Nathan Reed (which is pretty good, btw - I do not wish to make his answer less relevant by answering again), but I do not have enough reputation yet. Anyway, I just wanted to point out that you can try to use this Vector2D class from Kevin Lindsey: http://www.kevlindev.com/gui/math/vector2d/index.htm Include that ...



Only top voted, non community-wiki answers of a minimum length are eligible