A ball in a 2D volleyball game is described by 4 variables, x , y, dx and dy. What exactly does it mean by dx and dy?

  • 1
    \$\begingroup\$ Without providing more detail, it would just be a guess. They are variables. We do not know the variable type, nor do we know how they are used. You only provide the variable name. \$\endgroup\$
    – jgallant
    Nov 4 '16 at 9:37
  • \$\begingroup\$ I have unfortunately only these informations as in my post. \$\endgroup\$
    – Tkininter
    Nov 4 '16 at 9:45
  • \$\begingroup\$ My guess is that they are the delta position, or the previous position, of the ball. \$\endgroup\$
    – jgallant
    Nov 4 '16 at 9:48
  • \$\begingroup\$ I've seen this before, in computer graphics. Hopefully my diagrams provide more insight. \$\endgroup\$
    – Gnemlock
    Nov 4 '16 at 9:53
  • \$\begingroup\$ Typically, it means Delta. Or distance/difference moved. \$\endgroup\$
    – Krythic
    Nov 4 '16 at 17:28

I have encountered this, before, when dealing with computer graphics. In these cases, x and y are the co-ordinates for the center of the circle, while dx and dy are the dimensions (or commonly, the diameter) of the circle.

Diagram of a circle, displaying midpoint (x,y) and dimensions (DX by DY).

This seems especially valid in the described scenario, even if the volleyball would typically be a perfect circle (i.e. we only need a single diameter, as dx == dy). This is not always the case, in animation. A common practice for basic shapes is to simply alter the width or height with movement, to show greater animation.

A standard textbook diagram displaying the common dimension changes in an animated ball.


I guess it is the speed of the ball.

At each frame, you can update the coordinates of the ball by doing

x = x + dx;
y = y + dy;

You should not update the position as written above in real life. If you are doing this in a game loop you should always keep track of the "delta", the time between 2 frames. That way, even if users have a different FPS, the ball will still move the same.

The code will look like :

x = x + dx * delta;
y = y + dy * delta;

The more time between 2 frames, the more distance traveled by the ball.

  • \$\begingroup\$ Please note that if you want to check previous versions or changes to a post (including your own), you can click on the "edited x min ago" link. This is a better alternative then adding the "edit:" ammendments that are more commonly associated with forums. +1 for adding the info on why you would not just use position and speed; I see people miss that one a lot. \$\endgroup\$
    – Gnemlock
    Nov 4 '16 at 10:02

The dx and dy naming convention comes from calculus. In calculus you often find the derivative of a function which is often read as "the change in x" or "the change in y". These terms are notated using dx, dy, dz, etc. You can read more about it here.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.