Hot answers tagged geometry
47
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 ...
32
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 ...
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
...
22
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 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 ...
20
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 ...
18
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 ...
17
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 ...
16
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 ...
16
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
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 ...
11
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, ...
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. ...
10
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, ...
9
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 ...
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
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
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 ...
9
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 ...
8
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 ...
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 ...
8
You can define a workable area like the one in your question with three values:
float innerRadius;
float outerRadius;
float maxAngle;
These values will be based off a center point which may or may not be the player's position. The shape of the workable area depends on where you place this point.
In the example above the center position lies a certain ...
8
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 ...
7
The first step, as you guess, is to split the concave polygon into multiple convex ones. The reason for this is that you'll use the separating axis theorem, which only works on convex polygons.
SAT per se only works on two convex polygons. The "separating axis" in the name refers to the axes perpendicular to the edges of the polygon. Circles, unfortunately, ...
7
You can access the underlying BitmapData of a FlxSprite by using sprite.pixels or sprite.framePixels. You can then use BitmapData's drawing methods for simple things. If you need to draw a circle, you'll probably want to make a DisplayObject like a proper Sprite, draw on it using Graphics, and then use the BitmapData's draw() function to draw it onto the ...
7
You're spot on with your observations regarding the capabilities of a bitmap based collision approach.
This method provides a really easy way to edit your levels with any program that can output a bitmap (any image editing program). This system is also really flexible when you want to define different types of ground. Say green for mud, and red for a solid ...
7
Higher order (i.e. greater than 1st order) spline length parameterization has to be approximated; it cannot be represented directly, hence the fact that it's not easy to find direct solutions to this.
Some extant implementations (copy-paste code):
Using Chebyshev approximations, according to the authors, accuracy grows as curve size increases. Look at pp. ...
7
As the previous answers said, computing the length of a Bezier curve it's hard (impossible?). I would say that 100% of the games use an approximation of the length, which is pretty much always accurate enough.
A few month ago I implemented it using the proposed approach of breaking the curve into "small" segments and adding their length. There's an example ...
7
Yes; the feature that does this is called "stream-out". For D3D10, the documentation can be found here. It captures the geometry shader output to a vertex buffer you specify, which can then be re-used.
For OpenGL, the same functionality exists under the name "transform feedback". The relevant OpenGL spec can be found here.
Only top voted, non community-wiki answers of a minimum length are eligible
