Class Car

All Implemented Interfaces:
Graph.Graphic, NamedObjectOps

public class Car extends DirectedObject2D
Class representing a car. Starting at the center line of the car, let L be the distance from the rear wheels to the front wheels or some other reference point, with the distance measured perpendicular to the wheel base. If the front wheels move a distance Δs at an angle with the X axis of θt, and if the angle from a line perpendicular to the rear axis and pointing towards the front of the car and with the X axis is φ, then if the front wheels move a distance Δx, the rear wheels (which have to move perpendicular to their axis), will move a distance Δx cos (θt -φ) in the direction of the line perpendicular to the rear axis. Similar, the distance perpendicular to this line is Δs sin(φ - θt). This distance is positive when phi is decreasing, so the change in the angle φ is therefore -(Δs) sin (θt -φ) / L. As Δs goes to zero, one obtains the following differential equation

dφ/ds = - (sin (φ - θt)) / L

The angle θt can be computed using the BasicSplinePath2D methods BasicSplinePath2D.dxDu(double) and BasicSplinePath2D.dyDu(double) together with Math.atan2(double,double), with u determined by the BasicSplinePath2D method u(s). To have the vehicle oriented so that it moves backwards with increasing values of s, the differential equation is

dφ/ds = (sin (φ - θt))/L

and again the sign will change if the vehicle is moving in the direction of decreasing s.

  • Constructor Details

    • Car

      public Car(Animation2D a2d, String name, boolean intern)
      Constructor.
      Parameters:
      a2d - the animation
      name - the name of this object
      intern - true if the object is interned in the animation's name space; false otherwise.
  • Method Details

    • getLength

      public double getLength()
      Get the length of the vehicle.
      Returns:
      the length of the vehicle in meters
    • getWidth

      public double getWidth()
      Get the width of the vehicle.
      Returns:
      the width of the vehicle in meters
    • getHoodLength

      public double getHoodLength()
      Get the length of the hood.
      Returns:
      the length of the hood in meters
    • getWindshieldLength

      public double getWindshieldLength()
      Get the length of the windshield. The length is measure horizontally along the vehicle's axis (parallel to its direction of motion when moving in a straight line).
      Returns:
      the length of the windshield in meters
    • getRearOffset

      public double getRearOffset()
      Get the distance from the rear of the vehicle to the rear wheels.
      Returns:
      the distance from the rear of the vehicle to the rear wheels in meters
    • getDoorLength

      public double getDoorLength()
      Get the length of a door.
      Returns:
      the length of the door
    • getDoorWidth

      public double getDoorWidth()
      Get the width of a door.
      Returns:
      the width of a door.
    • getColor

      public Color getColor()
      Get the color of the vehicle.
      Returns:
      the color of the vehicle
    • getWindshieldColor

      public Color getWindshieldColor()
      Get the color of the windshield. The default is Color.WHITE, but in some cases it is useful to change it (e.g., for a white vehicle).
      Returns:
      the color of the windshield
    • setSkidMode

      public void setSkidMode(boolean mode)
      Set skid mode on or off. When skid mode is off (the default), an angle function is used that will prevent the car from "fishtailing" as it follows a path. Otherwise the angle the car makes with a path is determined by a user-specified angle function, or alternatively an angular velocity and angular acceleration, and whether the angle is absolute or relative (see DirectedObject2D.setAngleRelative(boolean)).
      Parameters:
      mode - true if skid mode is on; false if it is off
    • getSkidMode

      public boolean getSkidMode()
      Determine if skid mode is turned on.
      Returns:
      true of skid mode is in effect; false otherwise
    • setReverseMode

      public void setReverseMode(boolean reverse)
      Set reverse mode on or off. When reverse mode is on, and one of the car's setPath methods is called with the relative-angle flag set to true (the default for a car), the car's angle will be flipped by 180 degrees. In the case where the angle (relative to the tangent) is 0, the rear of the car will point in the same direction as the path's tangent vector.

      This method should not be called after setPath is called and before the car reaches its final point along the path: otherwise the behavior may be erratic.

      Parameters:
      reverse - true to turn reverse mode on; false to turn it off.
    • getReverseMode

      public boolean getReverseMode()
      Determine if reverse mode is turned on. When reverse mode is on, and one of the car's setPath methods is called with the relative-angle flag set to true (the default for a car), the car's angle will be flipped by 180 degrees. In the case where the angle (relative to the tangent) is 0, the rear of the car will point in the same direction as the path's tangent vector.
      Returns:
      true if reverse mode is in effect; false otherwise.
    • update

      protected void update(double t, long simtime)
      Overrides:
      update in class DirectedObject2D
    • setPathImplementation

      protected void setPathImplementation(BasicSplinePath2D path, double u0, double angle, boolean angleRelative, double time0)
      Set a path for this object to follow, specifying an initial path parameter and angle. The object's position will held at the start of the path until the object's time passes time0. The object's angle will match that of a tangent to the path at the object's reference point's current location. The path angle function will be set to null, as will the corresponding simulation function. If one is desired, it should be reset after setPath is called.

      Skid mode is recognized by this method. The implementation for skid mode installs a path-angle function, but keeps a copy of the previous one and restores it when skid mode is turned off. This method sets the saved value to null as the normal behavior of this method is to set the path angle function to null. A path simulation function is treated similarly.

      Subclasses that modify how paths are processed should override this method and in most cases call super.setPathImplementation and, of course, document any changes in behavior.

      Overrides:
      setPathImplementation in class DirectedObject2D
      Parameters:
      path - the path the object will follow
      u0 - the path's parameter at a time equal to time0
      angle - the initial angle
      angleRelative - true if the angle is measured relative to path's tangent; false if the angle is absolute
      time0 - the increment from the current time at which the object starts moving along the path
    • clearPath

      public void clearPath()
      Overrides:
      clearPath in class DirectedObject2D
    • configure

      public void configure(double length, double width, double hoodLength, double windshieldLength, double rearOffset, Color color) throws IllegalStateException
      Initialize the Car. All lengths are measured on a two-dimensional surface so that for any component (e.g., a windshield) that is slanted vertically, the length of the projection onto the x-y plane must be used. The door widths and lengths are set to zero to indicate that default values should be used.
      Parameters:
      length - the length of the car in meters
      width - the width of the car in meters
      hoodLength - the length of the hood in meters
      windshieldLength - length the length of the windshield in meters (measured horizontally)
      rearOffset - distance from the rear of the car to the rear wheels
      color - the color of the car
      Throws:
      IllegalStateException - attempt to change parameters after the car was configured
    • configure

      public void configure(double length, double width, double hoodLength, double windshieldLength, double rearOffset, Color color, double doorLength, double doorWidth) throws IllegalStateException
      Initialize the Car, specifying door dimensions. All lengths are measured on a two-dimensional surface so that for any component (e.g., a windshield) that is slanted vertically, the length of the projection onto the x-y plane must be used.
      Parameters:
      length - the length of the car in meters
      width - the width of the car in meters
      hoodLength - the length of the hood in meters
      windshieldLength - length the length of the windshield in meters (measured horizontally)
      rearOffset - distance from the rear of the car to the rear wheels
      color - the color of the car
      doorLength - the length of the door in meters
      doorWidth - the width (thickness) of the door in meters
      Throws:
      IllegalStateException - attempt to change parameters after the car was configured
    • configure

      public void configure(double length, double width, double hoodLength, double windshieldLength, double rearOffset, Color color, Color windshieldColor) throws IllegalStateException
      Initialize the object, also specifying a color for the windshield. All lengths are measured on a two-dimensional surface so that for any component (e.g., a windshield) that is slanted vertically, the length of the projection onto the x-y plane must be used.
      Parameters:
      length - the length of the car in meters
      width - the width of the car in meters
      hoodLength - the length of the hood in meters
      windshieldLength - length the length of the windshield in meters (measured horizontally)
      rearOffset - distance from the rear of the car to the rear wheels
      color - the color of the car
      windshieldColor - the color to use to represent the windshield
      Throws:
      IllegalStateException - attempt to change parameters after the car was configured
    • configure

      public void configure(double length, double width, double hoodLength, double windshieldLength, double rearOffset, Color color, Color windshieldColor, double doorLength, double doorWidth) throws IllegalStateException
      Initialize the object, also specifying a color for the windshield. All lengths are measured on a two-dimensional surface so that for any component (e.g., a windshield) that is slanted vertically, the length of the projection onto the x-y plane must be used.
      Parameters:
      length - the length of the car in meters
      width - the width of the car in meters
      hoodLength - the length of the hood in meters
      windshieldLength - length the length of the windshield in meters (measured horizontally)
      rearOffset - distance from the rear of the car to the rear wheels
      color - the color of the car
      windshieldColor - the color to use to represent the windshield
      doorLength - the length of the door in meters
      doorWidth - the width (thickness) of the door in meters
      Throws:
      IllegalStateException - attempt to change parameters after the car was configured
    • setRefPointByName

      public void setRefPointByName(RefPointName loc)
      Overrides:
      setRefPointByName in class PlacedAnimationObject2D
    • setRefPoint

      public void setRefPoint(double x, double y)
      Overrides:
      setRefPoint in class PlacedAnimationObject2D
    • setRefPointByFraction

      public void setRefPointByFraction(double xf, double yf)
      Overrides:
      setRefPointByFraction in class PlacedAnimationObject2D
    • setPathAngleByF

      public void setPathAngleByF(RealValuedFunctOps f)
      Overrides:
      setPathAngleByF in class DirectedObject2D
    • setPathAngleBySF

      public void setPathAngleBySF(SimFunction f)
      Overrides:
      setPathAngleBySF in class DirectedObject2D
    • setLeftDoorMode

      public void setLeftDoorMode(boolean mode)
      Set the mode for the door. After being set, the door's position will adjust, constrained by its angular speed.
      Parameters:
      mode - true if the door is open; false if closed.
    • getLeftDoorMode

      public boolean getLeftDoorMode()
      Get the left-door mode.
      Returns:
      true if the left door is configured to be open; false otherwise
    • setLeftDoorRate

      public void setLeftDoorRate(double angularSpeed) throws IllegalArgumentException
      Set the angular speed (absolute value of the angular velocity) at which a door opens or closes.
      Parameters:
      angularSpeed - the absolute value of the angular velocity while the door is moving in units of radians per second
      Throws:
      IllegalArgumentException - the argument was negative
    • getLeftDoorRate

      public double getLeftDoorRate()
      Get the angular rate at which the left door moves.
      Returns:
      the angular rate in radians per second
    • setLeftDoorMaxAngle

      public void setLeftDoorMaxAngle(double angle) throws IllegalArgumentException
      Set the maximum door angle for the left door. The value must be in the range [0.0, π).
      Parameters:
      angle - the angle in radians
      Throws:
      IllegalArgumentException - the angle was out of range
    • getLeftDoorMaxAngle

      public double getLeftDoorMaxAngle()
      Get the maximum angle for the left door when open.
      Returns:
      the angle in radians
    • setRightDoorMode

      public void setRightDoorMode(boolean mode)
      Set the mode for the door. After being set, the door's position will adjust, constrained by its angular speed.
      Parameters:
      mode - true if the door is open; false if closed.
    • getRightDoorMode

      public boolean getRightDoorMode()
      Get the right-door mode.
      Returns:
      true if the right door is configured to be open; false otherwise
    • setRightDoorRate

      public void setRightDoorRate(double angularSpeed) throws IllegalArgumentException
      Set the angular speed (absolute value of the angular velocity) at which a door opens or closes.
      Parameters:
      angularSpeed - the absolute value of the angular velocity while the door is moving in units of radians per second
      Throws:
      IllegalArgumentException - the argument was negative
    • getRightDoorRate

      public double getRightDoorRate()
      Get the angular rate at which the right door moves.
      Returns:
      the angular rate in radians per second
    • setRightDoorMaxAngle

      public void setRightDoorMaxAngle(double angle) throws IllegalArgumentException
      Set the maximum door angle for the right door. The value must be in the range [0.0, π).
      Parameters:
      angle - the angle in radians
      Throws:
      IllegalArgumentException - the angle was out of range
    • getRightDoorMaxAngle

      public double getRightDoorMaxAngle()
      Get the maximum angle for the right door when open.
      Returns:
      the angle in radians
    • setLookAngle

      public void setLookAngle(double angle)
      Set the angle the driver looks relative to the car An angle of zero points in the direction in which the car is pointed, and angles are measured counterclockwise in radians
      Parameters:
      angle - the angle
    • setLooking

      public void setLooking(boolean value)
      Set whether or not the word "Look", or the value provided by the method setLookString, should be displayed in front of the driver's location.
      Parameters:
      value - true if the string should be displayed, false otherwise.
    • setLookParams

      public void setLookParams(Color color)
      Set the font color for a "looking" indication.
      Parameters:
      color - the text color
    • getLookString

      public String getLookString()
      Get the string to display when setLooking is given the argument 'true'.
      Returns:
      the string to display
    • setLookString

      public void setLookString(String string)
      Set the string to display when setLooking is given the argument 'true'.
      Parameters:
      string - the string to display; null or an empty string for the default (the string "Look")
    • setDriverPosition

      public void setDriverPosition(double x, double y)
      Set the position of the driver. This method is used when blind spots are displayed, as the blind spots depend on the driver's location in the vehicle.
      Parameters:
      x - the distance in meters from the top of the windshield, towards the rear of the car
      y - the distance in meters from the left side of the car, towards the right side
    • setDriverX

      public void setDriverX(double x)
      Set the X coordinate of the driver. This method is used when blind spots are displayed, as the blind spots depend on the driver's location in the vehicle. It is provided primarily because factories may have to set the X and Y components of the driver's position indpendently.
      Parameters:
      x - the distance in meters from the top of the windshield, towards the rear of the car
      See Also:
    • getDriverXGCS

      public double getDriverXGCS()
      Return the X coordinate of a driver's position in graph coordinate space.
      Returns:
      the X coordinate in graph coordinate space
    • getDriverYGCS

      public double getDriverYGCS()
      Return the Y coordinate of a driver's position in graph coordinate space.
      Returns:
      the Y coordinate in graph coordinate space
    • setDriverY

      public void setDriverY(double y)
      Set the Y coordinate of the driver. This method is used when blind spots are displayed, as the blind spots depend on the driver's location in the vehicle. It is provided primarily because factories may have to set the X and Y components of the driver's position indpendently.
      Parameters:
      y - the distance in meters from the left side of the car, towards the right side
      See Also:
    • getDriverX

      public double getDriverX()
      Get the horizontal distance to the driver from the top of the windshield.
      Returns:
      the distance in meters.
    • getDriverY

      public double getDriverY()
      Get the distance to the driver from the left side of the car.
      Returns:
      the distance in meters.
    • setLeftBlindSpotExtent

      public void setLeftBlindSpotExtent(double phiLeft)
      Set the left blind spot angular extent. The extent (angular width) is in units of radians.
      Parameters:
      phiLeft - the angular width of the left blind spot
    • getLeftBlindSpotAngle

      public double getLeftBlindSpotAngle()
      Get the left blind-spot angle.
      Returns:
      the left blind-spot angle in radians
    • getLeftBlindSpotExtent

      public double getLeftBlindSpotExtent()
      Get the left blind-spot angular extent.
      Returns:
      the left blind-spot angular width in radians
    • setRightBlindSpotExtent

      public void setRightBlindSpotExtent(double phiRight)
      Set the right blind spot angular extent. The angular extend (angular width) of the blind spot is in units of radians.
      Parameters:
      phiRight - the angular width of the right blind spot
    • getRightBlindSpotAngle

      public double getRightBlindSpotAngle()
      Get the right blind-spot angle.
      Returns:
      the right blind-spot angle in radians
    • getRightBlindSpotExtent

      public double getRightBlindSpotExtent()
      Get the right blind-spot angular extent.
      Returns:
      the right blind-spot angular width in radians
    • setLeftBlindSpotOffset

      public void setLeftBlindSpotOffset(double offset)
      Set the left blind-spot offset. The center of the blind spot is located at an angle θ = arctan (y/x) where y = driverY, x = driverX + windshieldLength - offset, and the angle is measured counterclockwise from the car's centerline.
      Parameters:
      offset - the offset in units of meters
    • getLeftBlindSpotOffset

      public double getLeftBlindSpotOffset()
      Get the left blind-spot offset. The center of the blind spot is located at an angle θ = arctan (y/x) where y = driverY, x = driverX + windshieldLength - offset, and the angle is measured counterclockwise from the car's centerline.
      Returns:
      the offset in units of meters.
    • setRightBlindSpotOffset

      public void setRightBlindSpotOffset(double offset)
      Set the right blind-spot offset. The center of the blind spot is located at an angle θ = arctan (y/x) where y = width - driverY, x = driverX + windshieldLength - offset, and the angle is measured clockwise from the car's centerline.
      Parameters:
      offset - the offset in units of meters
    • getRightBlindSpotOffset

      public double getRightBlindSpotOffset()
      Get the right blind-spot offset. The center of the blind spot is located at an angle θ = arctan (y/x) where y = width - driverY, x = driverX + windshieldLength - offset, and the angle is measured clockwise from the car's centerline.
      Returns:
      the offest in units of meters
    • setLeftBlindSpotLength

      public void setLeftBlindSpotLength(double leftLength)
      Set the length of the left blind spot as displayed. The length is the height of the triangle used to depict the blind spots.
      Parameters:
      leftLength - the length in meters for the left blind spot
    • setRightBlindSpotLength

      public void setRightBlindSpotLength(double rightLength)
      Set the length of the left blind spot as displayed. The length is the height of the triangle used to depict the blind spots.
      Parameters:
      rightLength - the length in meters for the right blind spot
    • getLeftBlindSpotLength

      public double getLeftBlindSpotLength()
      Get the left blind-spot length. This length is the height of the triangle used to display the blind spot.
      Returns:
      the length in meters.
    • getRightBlindSpotLength

      public double getRightBlindSpotLength()
      Get the right blind-spot length. This length is the height of the triangle used to display the blind spot.
      Returns:
      the length in meters.
    • setBlindSpotColor

      public void setBlindSpotColor(Color c)
      Set the blind spot color.
      Parameters:
      c - the color; null for a default
    • getBlindSpotColor

      public Color getBlindSpotColor()
      Get the color used to display a blind spot.
      Returns:
      the color
    • setLeftBlindSpotVisible

      public void setLeftBlindSpotVisible(boolean visibility)
      Set whether or not the left blind spot is displayed.
      Parameters:
      visibility - true if the blind spot is displayed; false if the blind spot is not displayed
    • getLeftBlindSpotVisible

      public boolean getLeftBlindSpotVisible()
      Determine if the left blind spot should be displayed.
      Returns:
      true of the left blind spot should be displayed; false if the left blind spot should not be displayed
    • setRightBlindSpotVisible

      public void setRightBlindSpotVisible(boolean visibility)
      Set whether or not the right blind spot is displayed.
      Parameters:
      visibility - true if the blind spot is displayed; false if the blind spot is not displayed
    • getRightBlindSpotVisible

      public boolean getRightBlindSpotVisible()
      Determine if the right blind spot should be displayed.
      Returns:
      true of the right blind spot should be displayed; false if the right blind spot should not be displayed
    • addTo

      public void addTo(Graph graph, Graphics2D g2d, Graphics2D g2dGcS)
    • printConfiguration

      public void printConfiguration(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print the configuration for an instance of Car. The documentation for method SimObject.printConfiguration(String,String,boolean,java.io.PrintWriter) contains a description of how this method is used and how to override it. The method DirectedObject2D.printConfiguration(String,String,boolean,java.io.PrintWriter) describes the data that will be printed for the superclass of this class. The data that will be printed when this method is called is the following.

      For class Car:

      • the length of the car.
      • the width of the car.
      • the length of the windshield (measured horizontally).
      • the rear offset.
      • the color.
      • the windshield color.
      • whether no-skid mode is active.
      • whether the car is in reverse.
      Overrides:
      printConfiguration in class DirectedObject2D
      Parameters:
      iPrefix - the prefix to use for an initial line when printName is true with null treated as an empty string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • printState

      public void printState(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print the state for an instance of Car. The documentation for method SimObject.printState(String,String,boolean,java.io.PrintWriter) contains a description of how this method is used and how to override it. The method DirectedObject2D.printState(String,String,boolean,java.io.PrintWriter) describes the data that will be printed for the superclass of this class. The data that will be printed when this method is called is the following.

      For class Car:

      • whether no-skid mode is in effect.
      • whether the car is in reserve.
      Overrides:
      printState in class DirectedObject2D
      Parameters:
      iPrefix - the prefix to use for an initial line when printName is true with null treated as an empty string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • isInterned

      public boolean isInterned()
      Specified by:
      isInterned in interface NamedObjectOps
    • getObjectNamer

      protected Simulation getObjectNamer()
    • getName

      public final String getName()
      Specified by:
      getName in interface NamedObjectOps
    • canDelete

      public boolean canDelete()
      Specified by:
      canDelete in interface NamedObjectOps
    • delete

      public final boolean delete()
      Specified by:
      delete in interface NamedObjectOps
    • isDeleted

      public final boolean isDeleted()
      Specified by:
      isDeleted in interface NamedObjectOps
    • deletePending

      public final boolean deletePending()
      Specified by:
      deletePending in interface NamedObjectOps