Each instance of this class represents movement in the context of a two-dimensional plane. A velocity is a combination of a smile.modeling.Direction of movement with a speed (a non-negative Double).
Another way to think about a Velocity is to divide it in two components: dx and dy. dx indicates the amount (and direction) of movement along the x-axis. dy is the same for the y-axis. The x coordinate increases rightwards and y downwards. For instance, a velocity with a dx of 10 and a dy of zero indicates rightward movement, and a velocity with a dx of -100 and a dy of -100 indicates faster movement leftwards and upwards.
There are many ways to create a Velocity using the methods on the companion object. Among other things, you can:
- construct a velocity from a direction and a (positive or zero) speed, as in
Velocity(Direction.Left, 50), - construct a velocity from
dxanddy, as inVelocity(-100, 50), or - determine the velocity needed to go from one smile.modeling.Pos to another in a single unit of time, as in
Velocity.between(pos1, pos2).
Many of the methods on Velocity objects also create and return new velocities.
Velocity objects are immutable.
Value parameters
- speed
-
the speed of movement, which cannot be negative
Attributes
- Companion
- object
- Source
- Velocity.scala
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
Returns a velocity whose speed equals this velocity’s speed multiplied by the given number, which must be positive or zero. The direction is the same.
Returns a velocity whose speed equals this velocity’s speed multiplied by the given number, which must be positive or zero. The direction is the same.
Attributes
- Source
- Velocity.scala
Sums this velocity with the given one. The sum’s dx equals the sum of the two dxs. The same goes for dy.
Sums this velocity with the given one. The sum’s dx equals the sum of the two dxs. The same goes for dy.
Attributes
- Source
- Velocity.scala
Subtracts the given velocity from this one. The result’s dx equals the difference between the two dxs. The same goes for dy.
Subtracts the given velocity from this one. The result’s dx equals the difference between the two dxs. The same goes for dy.
Attributes
- Source
- Velocity.scala
Returns a velocity whose speed equals this velocity’s speed divided by the given number, which must be positive. The direction is the same.
Returns a velocity whose speed equals this velocity’s speed divided by the given number, which must be positive. The direction is the same.
Attributes
- Source
- Velocity.scala
Returns a velocity that has the given direction and the same speed as this one.
Returns a velocity that has the given direction and the same speed as this one.
Attributes
- Source
- Velocity.scala
Returns a velocity that has the given speed and the same direction as this one.
Returns a velocity that has the given speed and the same direction as this one.
Attributes
- Source
- Velocity.scala
Returns a velocity whose direction is the given number of degrees clockwise from this one’s. The speed is the same.
Returns a velocity whose direction is the given number of degrees clockwise from this one’s. The speed is the same.
Attributes
- Source
- Velocity.scala
Returns a velocity whose direction is the given number of degrees counterclockwise from this one’s. The speed is the same.
Returns a velocity whose direction is the given number of degrees counterclockwise from this one’s. The speed is the same.
Attributes
- Source
- Velocity.scala
Returns a velocity whose speed equals this velocity’s speed plus the given number. The direction is the same.
Returns a velocity whose speed equals this velocity’s speed plus the given number. The direction is the same.
Attributes
- Source
- Velocity.scala
Determines whether the speed of this Velocity is precisely zero.
Returns the Pos that an object moving at this velocity reaches in one unit of time. That is, adds the dx and dy components of this velocity to the given Pos and returns the result.
Returns the Pos that an object moving at this velocity reaches in one unit of time. That is, adds the dx and dy components of this velocity to the given Pos and returns the result.
Attributes
- Source
- Velocity.scala
Returns a velocity whose speed is as close to this one’s as possible without exceeding the given number. The direction is the same.
Returns a velocity whose speed is as close to this one’s as possible without exceeding the given number. The direction is the same.
Attributes
- Source
- Velocity.scala
Returns a velocity whose speed is as close to this one’s as possible without being lower than the given number. The direction is the same.
Returns a velocity whose speed is as close to this one’s as possible without being lower than the given number. The direction is the same.
Attributes
- Source
- Velocity.scala
Returns a velocity that is equal to this one in speed but has the opposite direction. The expressions myVelocity.opposite and -myVelocity are equivalent.
Returns a velocity that is equal to this one in speed but has the opposite direction. The expressions myVelocity.opposite and -myVelocity are equivalent.
Attributes
- Source
- Velocity.scala
Returns a String description of the Velocity. E.g., "111.80 with direction dx=0.89,dy=-0.45". Uses two decimals for each number.
Returns a String description of the Velocity. E.g., "111.80 with direction dx=0.89,dy=-0.45". Uses two decimals for each number.
Attributes
- Source
- Velocity.scala
Returns a velocity whose speed equals this velocity’s speed minus the given number. The direction is the same.
Returns a velocity whose speed equals this velocity’s speed minus the given number. The direction is the same.
Attributes
- Source
- Velocity.scala
Returns a velocity whose direction equals this one’s but whose speed is zero.
Returns a velocity whose direction equals this one’s but whose speed is zero.
Attributes
- Source
- Velocity.scala
Returns a velocity whose dx is the opposite of this one’s. The dy is the same, as is the speed.
Returns a velocity whose dx is the opposite of this one’s. The dy is the same, as is the speed.
Attributes
- Source
- Velocity.scala
Returns a velocity whose dy is the opposite of this one’s. The dx is the same, as is the speed.
Returns a velocity whose dy is the opposite of this one’s. The dx is the same, as is the speed.
Attributes
- Source
- Velocity.scala
Returns a smile.modeling.Pos whose x and y components equal this velocity’s dx and dy, respectively.
Returns a smile.modeling.Pos whose x and y components equal this velocity’s dx and dy, respectively.
Attributes
- Source
- Velocity.scala
Returns a String description of the Velocity. The format varies depending on the velocity’s direction.
Returns a String description of the Velocity. The format varies depending on the velocity’s direction.
Attributes
- See also
- Definition Classes
-
Any
- Source
- Velocity.scala
Returns a velocity that is equal to this one in speed but has the opposite direction. The expressions -myVelocity and myVelocity.opposite are equivalent.
Returns a velocity that is equal to this one in speed but has the opposite direction. The expressions -myVelocity and myVelocity.opposite are equivalent.
Attributes
- Source
- Velocity.scala
Inherited methods
An iterator over the names of all the elements of this product.
An iterator over the names of all the elements of this product.
Attributes
- Inherited from:
- Product
- Source
- Product.scala
An iterator over all the elements of this product.
An iterator over all the elements of this product.
Attributes
- Returns
-
in the default implementation, an
Iterator[Any] - Inherited from:
- Product
- Source
- Product.scala
Concrete fields
the amount of change in the x coordinate when moving at this velocity for one unit of time
the amount of change in the x coordinate when moving at this velocity for one unit of time
Attributes
- Source
- Velocity.scala
the amount of change in the y coordinate when moving at this velocity for one unit of time
the amount of change in the y coordinate when moving at this velocity for one unit of time
Attributes
- Source
- Velocity.scala
