# Tag Info

69

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

53

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

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

35

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.

32

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

32

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

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

26

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

24

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 kinked. If we measure using the distance from ...

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

18

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

17

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

17

First, we can convert your source rectangles to cells in your underlying grid, to make the input more uniform. (Effectively rasterizing the problem) This will let us find optimizations that might not be obvious when working directly with the source rectangles - particularly when it involves splitting multiple source rectangles to recombine them differently. ...

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

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

Actually no, the 'job' of the geometry shader (GS) is primative evaluation. Geometry shaders can tesselate, but they are limited by a) an in-process upper bounds on the number of output elements, and b) execution within a single shader...of course shader instancing aleviates the 2nd issue, but overall geometry shaders are more effective at primative ...

15

Others have pointed out how you can use the sign of the dot product to broadly determine the angle between two arbitrary vectors (positive: < 90, zero: = 90, negative: > 90), but there's another useful geometric interpretation if at least one of the vectors is of length 1. If you have one unit vector $\hat U$ and one arbitrary vector $V$, you can ...

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

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

13

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

13

How is Matrix Multiplication a Transformation? A matrix is just a big grid of numbers with rules that define how we can multiply it with other grids or lists of numbers. In games, we usually want to construct a matrix so that, when multiplied with a list of numbers representing a source position (say, the position of a vertex in a mesh) we get a list of ...

12

I'd say you are on the right track, but coming up with an optimal and/or efficient algorithm is another matter: it's a difficult problem. However, unless your interest is academic, a good-enough solution may suffice. First, if you are not interested in coming up with your own solution, CGAL contains an algorithm for convex polyhedra decomposition already: ...

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

Because spherical maps, compared to rectangular ones, create a lot of additional complexities regarding the technical implementation and the UI design while usually offering very little gameplay advantage. First, there is the technical problem. With a rectangular map, you just use a 2-dimensional array to represent map positions. But unfortunately there is ...

11

2D hexagonal maps are a representation of spheres packed in a flat (2D) tray, with each hex centred on the equivalent sphere, and allow distances between cells to be determined to workable (for gaming purposes anyway) accuracy, just by counting the number of hex cells through which you step. The equivalent 3D representation is the face-centred cubic (FCC)/...

10