public class Graph extends AbstractCompositeShape
A 2D graph visualization rendered in 3D space.

Plots a series of Point2D data points as a connected line graph, overlaid on a grid with horizontal and vertical grid lines, axis labels, and a title. The graph is rendered in the XY plane at the specified 3D location, with all dimensions scaled by a configurable scale factor.

The graph uses the following default configuration:

  • X-axis range: 0 to 20 (world units before scaling)
  • Y-axis range: -2 to 2
  • Grid spacing: 0.5 in both horizontal and vertical directions
  • Grid color: semi-transparent blue (rgba(100, 100, 250, 100))
  • Plot color: semi-transparent red (rgba(255, 0, 0, 100))

Usage example:


 // Prepare data points
 List<Point2D> data = new ArrayList<>();
 for (double x = 0; x <= 20; x += 0.1) {
     data.add(new Point2D(x, Math.sin(x)));
 }

 // Create a graph at position (0, 0, 500) with scale factor 10
 Graph graph = new Graph(10.0, data, "sin(x)", new Point3D(0, 0, 500));

 // Add to the scene
 shapeCollection.addShape(graph);
 
See Also:
  • Constructor Details

    • Graph

      public Graph(double scale, List<Point2D> data, String label, Point3D location)
      Creates a new graph visualization at the specified 3D location.

      The graph is constructed with grid lines, axis labels, plotted data, and a title label. All spatial dimensions are multiplied by the given scale factor.

      Parameters:
      scale - the scale factor applied to all spatial dimensions of the graph
      data - the list of 2D data points to plot; consecutive points are connected by lines
      label - the title text displayed above the graph
      location - the 3D position of the graph's origin in the scene