Tag Info

Hot answers tagged

54

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 ...


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 ...


27

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 ...


25

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

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 ...


23

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

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 ...


21

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 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 “origin of ...


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 ...


17

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 ...


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 ...


13

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, ...


13

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 ...


13

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) ...


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, ...


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.


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

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.


10

edit: source shader code tested, updated and works... there is also video... Once you use a 3D coord instead 2D to sample cube, it is possible (but not parametric :)). First theory: Use normalize(GL_Vertex - cubeOrigin) as sampling vector. You have to know to which face of cube vertex belongs. It is the biggest componnent in sampling vector. Once ...


10

Measuring the length of a Bezier curve is hard. If you don't mind a slight inaccuracy, a simple solution would be to approximate the Bezier curves with straight lines and calculate the sum of the line lengths. The more segments you create, the better the approximation.


10

Let A and B be two points on the black line. Let C and D be your blue segment. The sign of the z coordinate of cross product AB^AC tells you whether C is "left" or "right" of the black line. Similarly, cross product AB^CD tells you whether CD steers "left" or "right" of the black line. We don't really want to know whether it's left or right; all we want is ...


10

To actually answer your question: the manhatten distance is consistent when you're constrained to moving vertically/horizonally along an unweighted grid (this can be easily shown by the definition on wikipedia). So yes, in your case you can avoid rechecking nodes in the closed set. However, once you allow diagonal or any-angle movement, manhatten distance ...


10

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 ...


9

There are a few things to consider here. The first is that a face is not necessarily rotated just because its normal is not aligned with an axis. The second is that you can't obtain Euler angles (x,y,z rotations) from just a normal. You would need to know at least 2 non collinear vectors to do that as you need three perpendicular vectors (a basis in R3) to ...


9

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 ...


9

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 ...


9

I was thinking how the problem could be solved if the shape was irregular, and one couldn't define it mathematically. Warning: this is a dirty solution, not for the faint of heart. 1. Take your area: 2. And convert it to a monochromatic bitmap: and name it scale_0 3. Clone the bitmap and scale it down to 50%: and name it scale_1 4. And so on, until ...


8

Models in Minecraft are hard-coded. There is no notion of block hierarchy (only a list of blocks). This means animations are either done procedurally (in a very basic way) or hard-coded values with interpolation. There are a few editors for Minecraft models like Techne or FMCModeler which allow importing / exporting Minecraft model code for mods, but they ...


8

What you're looking for is called the Separating Axis Theorem. A tutorial of it can be found here. Essentially what you want to do, in the case of Object Oriented Bounding Boxes (rotated squares) is project the half-vectors of those squares, let's say 'up' and 'right,' onto the axes in the coordinate spaces of each square. You also project the vector ...



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