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

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

52

No this isn't an engine bug or an artifact of a particular rotation representation (those can happen too, but this effect applies to every system that represents rotations, quaternions included). You've discovered a real fact about how rotation works in three-dimensional space, and it departs from our intuition about other transformations like translation: ...

36

Does that mean that the magnitude is simply it is distance from the origin point (0, 0, 0)? That's exactly that. Among other things, a vector can represent a point (a position), a direction and/or a velocity, depending on the context. If you have this variable: Vector3 mPosition; It generally represents only the position, i.e. where it is located in ...

34

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

31

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

31

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

31

You can use Gauss' shoelace formula: You need to take the x coordinate of every point, multiply them by the next point's y coordinate, then subtract the current point's y coordinate multiplied by the next point's x coordinate from the result and add them to the total area. After you did this for every point, halve the total area to get the actual area of ...

29

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.

28

You could easily find the normal by calculating two vectors, V1 = P2-P1, and V2 = P3-P1, and then find the cross product N = V1 x V2. Then you normalize N. Depending on the ordering of the vertices (clockwise or counterclockwise) you will get a normal facing front or back. You also need to make sure that three three points aren't aligned, if they are you ...

27

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

27

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

26

If (x,y) is the centre of the rectangle, 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.

23

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

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

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

20

Does that mean that the magnitude is simply it is distance from the origin point (0, 0, 0)? The tl;dr answer may be: Yes, you can imagine it like that. But I'm not sure whether this might not lead to a wrong understanding. A vector is not a point, and there is a crucial difference between the two! The fact that a vector is usually represented as an "...

20

It doesn't work well to do depth tests at the vertex level. Triangles are surfaces. All three vertices of a triangle could be occluded by other triangles in the scene and the middle of that triangle could still be visible. The only way to determine whether that triangle is completely behind something else is to interpolate position or depth along the ...

19

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

19

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

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

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

16

A simple way to build a procedural generator is: Randomly build things Run a function that checks whether the output is good If the output is not good, go to step 1 Even if it takes thousands of runs to complete, most simple generators get by just fine with this approach. The advantage is that there's not a lot of smarts required in the generator, and ...

15

With i going from 0 to n-1 inclusive: pointX[i] = ( sin( i / n * 2 * PI ) * radius ) + xOffset; pointY[i] = ( cos( i / n * 2 * PI ) * radius ) + yOffset; Edit: As Lars Viklund mentioned in the comments, this is only safe in languages like javascript in which integer division returns a floating point number rather than a integer. In other languages you ...

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

The circumcenter of a triangle can be found by the following formula, which I mined from an old posting by Jonathan Shewchuk from the Geometry Junkyard \begin{align} &\text{Triangle in } \Bbb R^3\text{:}\\ &m = a + \frac {\lVert c-a\rVert^2 \left[(b-a) \times (c - a) \right] \times (b-a) + \lVert b-a\rVert^2 \left[(c-a) \times (b - a) \right] \...

15

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

14

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

14

The problem here is that Populous maps are not spheres at all. They're a Real Projective plane, more analogous to a flat torus manipulated on screen to look like a sphere than an actual sphere. For example: Populous maps are squares when viewed outside of the populous engine Populous maps ingame are visibly warped to show/hide the curvature by moving from ...

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

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