Questions tagged [mathematics]

Mathematics questions deal with the arithmetic, geometry, calculus, formulae and other calculations used in the development of a game.

This tag is for questions about the math needed to produce some result in a game. These questions can involve complete formulae and algorithms, or they could just be about the math for a particular step in the process. Examples of mathematics questions include:

  • Create a formula for damage given different present variables
  • Determine the change in momentum for two objects after a collision
  • Find the largest parabolic distance for a projectile path
  • Produce specific beautiful, scintillating patterns of colorful bullet death

For questions specifically about using a complete algorithm to achieve a specific result, you can also use .

Resources:

1989 questions
54
votes
4 answers

How are imaginary numbers useful in video game creation?

I learned about imaginary numbers in school and they seemed so impractical, so I asked my teacher what they were used for and he said "video game creation". I just want to know if this is true and if so how is it used during the creation process.
Daosof
  • 651
  • 1
  • 6
  • 13
49
votes
7 answers

What are atan and atan2 used for in games?

I am having some trouble understanding Math.tan() and Math.atan() and Math.atan2(). I have basic knowledge of trigonmetry but the usage of SIN, COS, and TAN etc for game development is very new to me. I am reading on some tutorials and I see that by…
sutoL
  • 601
  • 1
  • 6
  • 7
23
votes
6 answers

What are some methods to represent train tracks?

I looked into this a while back for a small project, but didn't get too far. I'd like to create a small program that lets a user draw a train track and then allows a "train" to follow said track on a 2D plane. I'd like the track to be pretty free…
hokiecsgrad
  • 2,496
  • 3
  • 21
  • 14
23
votes
6 answers

How to convert a number from one min\max set to another min\max set?

I'm doing terrain generation and I have a perlin library that is giving me random numbers between -1 and +1. I want to convert this to the scale of 0-255. What is the proper way to do this?
Thraka
  • 465
  • 1
  • 3
  • 20
23
votes
1 answer

How can I evenly fan out a hand of cards?

Given a set of playing cards (rectangle images with a width and height) how can I rotate and position each one so that they appear in a 'fan' pattern, much like you would hold a hand of cards in real life. What math is needed to do this? UPDATE Here…
Sembiance
  • 333
  • 2
  • 7
15
votes
3 answers

Get angle in radians given a point on a circle

I'm working on a dial that rotates around a circle. This dial should lets you mousemove anywhere in a circle to adjust the position of the dial to a point on the circle with the same angle as the click. For example, from the dial above if you…
editor
  • 253
  • 1
  • 2
  • 6
11
votes
4 answers

How can I compare two quaternions for logical equality?

I'm trying to write some unit tests and realize I don't know how to compare quaternions. I need to know if two quaternions represent the same orientation (the object would be facing the same way). With a vector like position I'd simply compare the…
edA-qa mort-ora-y
  • 1,340
  • 4
  • 13
  • 21
11
votes
2 answers

How to make the player slide smoothly against terrain

I'm making an isometric game. When the player tries to walk diagonally into a wall I want them to slide smoothly across it, so whatever portion of the movement would be legal is used, and anything in the direction of the normal is thrown away.…
Iain
  • 6,518
  • 3
  • 33
  • 46
9
votes
5 answers

Can a straight line be called a polygon?

According to the definition of Polygon, If a Poly-line's first and last points are connected then it is called Polygon. See the image below. I have P1, .... P5 Polyline. If I draw a line from P5 to P1 then it will be called polygon or not? I am…
8
votes
3 answers

How to smoothly let an object move along a curved line

I'm wondering how to move objects, with rotation taken into account, to follow a curved line see: http://www.youtube.com/watch?v=iPpO24FeAX4 for an example In particular I wonder: how to store the points, how many points to store for a smooth…
user2530
  • 81
  • 1
  • 3
7
votes
3 answers

Create acceleration with direction

I want to move my object with an acceleration in the proper direction. For example if I have these values: friction = 0.3; direction = 180; speed = 5; For making it clear, I need a formula to create a linear acceleration.
MahanGM
  • 367
  • 4
  • 22
6
votes
1 answer

How do I go from world coordinates (X/Y) to tile coordinates?

So, I've got this game rendered in fake isometric view with the following code for generating the mesh: _x = x + ( y & 1 > 0 ? 0 : 0.5 ); _y = y * 0.25; ADD_VERTICES( [ _x-0.5, _y, 0, _uv[0], _uv[3], //B _x, _y+0.25, 0, …
Elva
  • 3,223
  • 1
  • 20
  • 31
5
votes
2 answers

Is there a better way of determining direction to turn?

You have an entity A that you want to turn towards another entity B. One way to determine the direction to turn is to compute the cross-product of the direction vector of A with the vector from AB. If the value of z is positive, then you turn…
Paul Kelly
  • 462
  • 5
  • 12
5
votes
2 answers

Drawing a line from a random coordinate through a given point

When the mouse button is clicked, I want to draw a line from (0, random) to (640, y) which goes through the click position. How would I calculate the y coordinate of the end of the line?
user2566
5
votes
2 answers

Simplified math formula to calculate stock price based on supply/demand

I am making an overly simplified version of a stock simulator game, because I: am fascinated with how the stock market works learn better & faster from a project like this, rather than text-books Before writing any actual code, I started making an…
leo.vingi
  • 195
  • 1
  • 5
1
2 3 4 5 6 7