# Tag Info

55

This can be explained with the Pythagorean Theorem, which is the following formula: a² + b² = c² In your case, when moving right, you're using (x:1, y:0) which gives us c² = 1 + 0 = 1 c = sqrt(1) = 1.00 When moving up and right, you're using (x:1, y:1) which gives us c² = 1 + 1 = 2 c = sqrt(2) = 1.41 So as you can see, the length diagonally is ...

52

A perfectly straight line would also be the shortest possible line with a total length of sqrt((x1-x2)² + (y1-y2)²). A more scribbly line will be a less ideal connection and thus be inevitably longer. When you take all individual points of the path the user drew and sum up the distances between them, you can compare the total length with the ideal length. ...

30

Yes, the Manhattan distance between two points is always the same, just like the regular distance between them. You can think of the Manhattan distance being the X and Y components of a line running between the two points. This image (from Wikipedia) illustrates this well: The green line is the actual distance. The blue, red and yellow lines all ...

30

This might not be the best way to implement this either, but I suggest a RMSD (root mean square deviation) could be better, than merely the distance method, in cases mentioned by Dancrumb (see first two lines below). RMSD = sqrt(mean(deviation^2)) Note: The sum of the absolute deviations (integral-like) might be better, as it does not average out ...

29

The solution is actually simpler than expected. The trick is to use Minkowski subtraction before your hexagon technique. Here are your rectangles A and B, with their velocities vA and vB. Note that vA and vB aren't actually velocities, they are the distance traveled during one frame. Now replace rectangle B with a point P, and rectangle A with rectangle ...

27

There are two general approaches: The leftmost is termed the uv-sphere and the rightmost an icosphere. GLUT tends to use the uv approach: look at the function glutSolidSphere() in the freeglut sourcecode. Here is an excellent article on producing an icosphere: http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html The uv-sphere ...

26

there are two cases of this problem. First is the intersection and second that is overlaping (containing). First (intersection / polygon inside circle): Find closest point on every edge of the polygon to the circle's center. If any distance between closest point to the center is less than radius, you got intersection or overlap. Second (circle is whole in ...

26

Draw a line to infinity and count how many times you cross the shape (even or odd), not counting the segment where the creature lies. Then check whether the creature is going left or right of that line. In this example, we cross the shape twice (so even) and we go to the left. The result is immediate from this table: # Crosses | even | odd ...

24

You've miswritten the formula. x = x * sqrtf(1.0 - (y*y/2.0) - (z*z/2.0) + (y*y*z*z/3.0)); y = y * sqrtf(1.0 - (z*z/2.0) - (x*x/2.0) + (z*z*x*x/3.0)); z = z * sqrtf(1.0 - (x*x/2.0) - (y*y/2.0) + (x*x*y*y/3.0)); You modify the original x and overwrite it. Then you modify y based not on the original x but the modified x. Then you modify z based on the ...

22

The four-variable representation of a plane is the coefficients in the equality ax + by + cz = d This can be seen as N = (a, b, c) being a normal vector and d being a distance from the coordinate origin (in units of the-length-of-N), and we can also write this equation as N·P = d, where P = (x, y, z). This representation does not allow defining a specific ...

22

Existing answers do not take into account that the end points are arbitrary (rather than given). Thus, when measuring the straightness of the curve, it does not make sense to use the end points (for example, to calculate expected length, angle, position). A simple example would be a straight line with both ends kincked. If we measure using the distance from ...

18

As others have said, yes the models as well as the animations are hard-coded. If you would like to see how this was done, go to the Minecraft Coder Pack wiki. The package was created to help mod creators to decompile, change and recompile the Minecraft classes. Instructions are included in the readme files which come with the package. The package ...

18

The segment running from A to B can be computed as P(t) = A + D · t where D is B - A and t runs from 0 to 1 Now the circle is centered on the origin (move A and B if necessary to put the center in the origin) and has radius r. You have an intersection if for some t you get that the P has the same length of r or, equivalently, that the length of P ...

18

You simply need to project vector AP onto vector AB, then add the resulting vector to point A. Here is one way to compute it: A + dot(AP,AB) / dot(AB,AB) * AB This formula will work in 2D and in 3D. In fact it works in all dimensions.

17

Google and Wikipedia tag team to the rescue: Tessellation and, more specific for 3D, Honeycomb is the term to look for. Cubes are indeed the only regular (all faces are congruent) AND space-filling (no gaps left as with sphere packing) polyhedra in 3D space. But they have the same problem as 2D squares - widely varying distances to its neighbors. A ...

15

It seems to me that having the center of your space be (0, 0, 0) is better. Assuming you are using a signed format to represent positions in space, a center of (0, 0, 0) allows you to use both the negative and positive parts of your format, which can do wonders for precision for floats and range for signed integers. This may not matter for small scales, but ...

15

dot(A,B) = |A| * |B| * cos(angle) which can be rearranged to angle = arccos(dot(A,B) / (|A|* |B|)). With this formula, you can find the smallest angle between the two vectors, which will be between 0 and 180 degrees. If you need it between 0 and 360 degrees this question may help you. By the way, the angle between two parallel vectors pointing in the ...

14

First of all, in the case of axis-aligned rectangles, Kevin Reid's answer is the best and the algorithm is the fastest. Second, for simple shapes, use relative velocities (as seen below) and the separating axis theorem for collision detection. It will tell you whether a collision happens in the case of linear motion (no rotation). And if there's rotation, ...

14

Given a "root" curve, here's how you might generate block vertices. The root curve is in the middle, in black. Its control points are shown with red Xs. In short: I made a Bézier and sampled it (at a configurable rate). I then found the perpendicular vector of the vector from each sample to the next, normalised it, and scaled it to to a (configurable) ...

13

I recently had to solve this myself for a WebGL application. I've attached the complete source code, but incase it doesn't work right off the bat for you here are some debugging tips: Don't debug your unproject method in your game. If possible, try to write unit-test style tests to make it easier to isolate what is going wrong. Be sure to print the output ...

12

Normalize your direction vector before use. As explained by MindWorX, this can be simply understood, if your worried about your direction vectors possibly giving you grief, make sure they are unit vectors (magnitude/length of 1). Length(Vector2(1, 1)) == 1.4142135623730951 // first hint of grief Length(Vector2(1, 0)) == 1 Vector2(1, 1) * 2 == Vector2(2, 2)...

12

The squared distance from a point (px,py) to the rectangle's border can be computed this way: dx = max(abs(px - x) - width / 2, 0); dy = max(abs(py - y) - height / 2, 0); return dx * dx + dy * dy; If that squared distance is zero, it means the point touches or is inside the rectangle.

12

If A and B are both 2D vectors, then... direction = normalize(B - A) any point on the line = direction * distance + A Or you can just take normalize(B - A) * speed and add that to the projectile's position every frame.

12

I'll assume your t goes from 0 to 1. (If not, just multiply to scale it appropriately.) Figure out what proportion (0–1) each side is of the perimeter. (side length / total perimeter) To find how much of every side is “filled in” at time t, iterate through sides, subtracting their proportions until t is depleted to a negative value. That last edge (which ...

12

One way to do it, considering you want a 90° angle, is to find the cross product of the normal and gravity, normalize it, then cross that with the normal again. In your diagram, the first cross will produce a vector pointing into the screen, and the second cross will produce the flow vector. An interesting side-affect of using cross products is that ...

11

Let's complicate your spiral: be in your case f(t) := t, in mine f(t) := 1 (so i pay back my complications with simplifications :) If you want to go at a certain speed in this degenerate spiral (a circle) you have to know how long is your spiral in a round so you can say how much rounds per second do to be sure that your point travels with the desired ...

11

The basic idea is to use a cross product to generate the extra orthogonal axes of your rotation matrix, based upon the axes that you already have. Matrix3x3 MakeMatrix( Vector3 X, Vector3 Y ) { // make sure that we actually have two unique vectors. assert( X != Y ); Matrix3x3 M; M.X = normalise( X ); M.Z = normalise( ...

11

Rather than finding the minimum distance to the nodes, find the minimum distance to the edge (ie the line segment defined by the nodes). Then, if the nearest point is a vertex (which you'll have to use some floating point epsilon** test), compare the angle between the line from new point to the vertex and each of the edges connected to that vertex. ...

11

I shall assume that your frustum is symmetrical, since your drawing seems to suggest so. There are three constraints (two if your frustum is 2D): A. the sphere cannot be larger than the distance between the near and far planes If D is the near-far distance, the first constraint is simply: R ≤ D / 2 B. the sphere cannot grow wider than the side planes ...

11

Sphere-Sphere Intersection Let's start with the more obvious one - sphere-sphere. It's almost identical to the circle-circle case in 2D. We can project down on any plane containing the line between the sphere's centers to get an identical 2D picture: Here the first sphere has center c_1 and radius r_1, the second c_2 and r_2, and their intersection has ...

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