# Tag Info

## Hot answers tagged coordinates

49

I think the direction of the coordinate axes are holdovers from different domains where the crucial plane was different, and X/Y were aligned with that crucial plane. In some applications the ground plane was the most important, thus X/Y were the ground and Z ended up perpendicular to that. For games however the crucial plane is usually the screen (...

47

This is caused in the history. Early computers had Cathode Ray Tubes (CRTs) which "draw" the image with a cathode ray from the upper left corner to the lower right. To ease the interface between the graphics card memory and the CRT the memory was read from the beginning and the image was drawn from the top left (with the lowest memory address) to the lower ...

29

Don't let a math major hear you calling Vectors points or coordinates! A 2D vector has an x and y component, not coordinate. Vectors do not define a position, they define a direction and a magnitude. I can't tell you why people are intimidated by them, likely the same reason people are intimidated by math in general, because everyone says it's hard before ...

23

First, here is the code. An explanation will follow: /* * tw, th contain the tile width and height. * * hitTest contains a single channel taken from a tile-shaped hit-test * image. Data was extracted with getImageData() */ worldToTilePos = function(x, y) { var eventilex = Math.floor(x%tw); var eventiley = Math.floor(y%th); if (hitTest[...

21

Okay, so Assuming that you know what the World Transformation matrix for that object A is, You just need to construct the inverse of that matrix and you will have what you need. Suppose the rotation, scaling and translation matrices of object A used to get it to Global Space are R, S and T respectively. You will multiply these together like S * R * T = W ...

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

11

In the image the red vector is the one we are trying to convert to cartesian, given angles phi & theta (in the description I will refer to the length of the vector as r, for radius of the sphere). So, the y-coordinate is the easy one, we know what the angle is between the red vector and the y-axis (phi), we just project the vector onto the y-axis; y=|...

10

r: radial distance θ: inclination φ: azimuth via Wikipedia public Vector3 getCartesianFor(float radius, float inclination, float azimuth) { return new Vector3(radius*Sin(inclination)*Cos(azimuth), radius*Sin(inclination)*Sin(azimuth), radius*Cos(inclination)); }

9

Before I answer the question you already asked, some notes: You can use A* with the original grid system you are using. The key things you need are neighbors and distance (for the heuristic). For neighbors with your grid system, you need to do something different for even and odd columns (as you mention); here's how: neighbors = [ [ [+1, +1], [+1, 0]...

9

I think the intimidation factor may arise when you start dealing with more complicated operations such as normalization, dot and cross products, and using multiple coordinate systems with matrices to transform between them. These are not necessarily easy to understand at first, even if you have a strong geometry and algebra background. Also, at least in ...

9

I've done this with trigonometry rather than matrixes in the past (I am a matrix noob). Ashes999's answer is halfway there, get the relative vector, then rotate that by the inverse of EntityA's angle. relativeX = B.x - A.x relativeY = B.y - A.y rotatedX = Cos(-Angle) * relativeX - Sin(-Angle) * relativeY rotatedY = Cos(-Angle) * relativeY + Sin(-...

8

If what you want is to bypass the floating inaccuracy caused by single point precision problem, for the sake of creating bigger environments for your game, then it depends on what you are willing to accept as a solution. Let's start by making this clear: it is impossible to alter the coordinate system at the inner core of Unity. So, you can't use double-...

8

The point P to be transformed is, in homogeneous coordinates: $$\begin{pmatrix} 50 \\ 40 \\ 1 \end{pmatrix}$$ The homogeneous transformation matrix M is (using $cos(\frac{\pi}{4}$) = sin($\frac{\pi}{4}) = 0.7071)$:  \begin{pmatrix} 0.7071 &0.7071 &-42.426 \\ -0.7071 &0.7071 &14.142 \\ 0 &0 & 1 \\ \end{...

8

My guess is you're trying to implement a camera, and should not be using SDL Viewports. The viewports are for UI elements like menus, minimaps, etc. It's a way of dividing up the screen into multiple areas. To implement a camera, you will want to think about coordinate systems. The world coordinates are the positions in the world, without thinking about the ...

7

You can normalize the first value, this will give you a value in the [0,1] range. You can think of that as X percentage, the percentage the value maps to between the minimum and maximum values. Then you can find where that percentage belongs in your destination coordinate system by seeing what value is X percentage through the destination system. I'll use ...

7

This depends on the combination of frameworks you are using. Sometimes a 2D game framework makes it very difficult to work with coordinates that are not bound to pixels because they were designed specifically for designers to think about their game world in pixel units. However, it's not a requirement. A game I'm currently working on relies on Box2D units ...

7

Vectors really aren't that bad. There is just a bit of math that people are unfamiliar with. First and foremost, a Vector does not represent a position in space. This is conceptually very important. A vector represents a direction, like 'North', and a magnitude. On a map with normal Math X-Y coordinates, 'North' would be the vector (0,1) (up on the Y ...

6

I'm not sure about OpenGL but DirectX allows you to over write the default left-handedness therefore it wouldn't matter. As you've said, it's "nothing but" a convention, and at least DirectX allows you to work with both. Conventions do not matter by themselves, the only problem is that you need to be consistent with your choice. Mixing two such systems leads ...

6

Unless your paths are parameterized based on lengths, then you'll have a bit of difficulty doing this. I'm going to give you a solution outline for paths containing only line segments, because distances are easy to calculate on line segments as they are with parameterizations. The setup I'm assuming there is that you have n + 1 points P_1, P_2, ..., P_{n}, ...

6

Your description is a bit vague, but it sounds like what you're trying to do is map coordinates from one space (the window coordinates) to another (your tile coordinate space). Doing so is a simple transformation using the window size: x_trans = x - (windowWidth / 2); y_trans = y - (windowHeight / 2); x_norm = x / (windowWidth / 2); y_norm = y / (...

6

Try using this Camera:unproject method: unproject(Vector3 screenCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) from the documentation: Function to translate a point given in screen coordinates to world space. It's the same as GLU gluUnProject, but does not rely on OpenGL. The x- and y-coordinate of vec are assumed ...

6

Let me try to give you something somewhere between The Light Spark's answer and Elliot's answer, because from what I read, you're really looking for an algorithm to follow and not just math tossed at you. Problem Statement: Given that you have a location A (50, 50) and a heading (since you didn't provide one, I'll assert it as y = 2 * x + 25), find where B (...

6

You're thinking in very static terms. Just because an object is half a world away doesn't necessitate any issues. If entity coordinates are stored relative to chunk rather than relative to world, this is trivial to achieve. Welcome to the way you'd have to do it if you were writing a voxel world in native code. So let's assume a concept called locales. It'...

6

That's a question that frequently pops up. I will take the liberty to forward you to another fairly detailed answer I already gave to the same issue, instead of just repeating it here: Is a custom coordinate system possible in Unity From there, what I would suggest the most is that you read the amazing paper at: http://citeseerx.ist.psu.edu/viewdoc/download?...

6

Triangulate the area. Pick a random triangle. Generate a random point inside that triangle (link).

5

I solved my own problem--and rather than just blow it off as a simple explanation, I want to describe the steps I took to debug the issue. I left out that I was using a single FBO for special-effects. First, it turns out everything above is in fact correct and a step I left out was the problem. I verified my orthogonal matrices through-and-through. ...

5

As a side-note, these coordinates make more sense if you interpret them as (Y, X). You can define a 'vertical line' (from bottom to right) as y = -0.5x + a And you can define a 'horizontal line' (from top to right) as y = 0.5x + b What you need is an algorithm to calculate A. You can obtain it from a grid drawing function - if you draw a line every 50 ...

5

Your question sounds a bit confused; there's no such thing as "the matrix of a point"; matrices just convert from one coordinate system to another. Did you mean that you have the two matrices that go from A to world coordinates, and B to world coordinates? And you want to find the matrix that converts from B to A? In that case, you'd just want B_to_world *...

5

It doesn't particularly matter. As long as you're consistent throughout your game. I believe the more common approach is to have the world bounds centered around (0,0), meaning you'd have your bounds go from -halfSize, halfSize. Since most data structures that represent position (Vector2 or Vector3) default to zeros, you know that the default placement for ...

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