2 * Sixth - System for data storage, computation, exploration and interaction.
3 * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.examples;
12 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
13 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
14 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.Graph;
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.List;
22 public class GraphDemo {
24 private static final double scale = 50d;
26 private static Graph getCosinusGraph(final Point3D location)
28 final List<Point2D> data = new ArrayList<>();
29 for (double x = 0; x < 20; x += 0.25) {
30 final double y = Math.cos(x);
32 final Point2D p = new Point2D(x, y);
36 return new Graph(scale, data, "Cosinus", location);
39 private static Graph getFormula1Graph(final Point3D location)
41 final List<Point2D> data = new ArrayList<>();
42 for (double x = 0; x < 20; x += 0.25) {
43 final double y = Math.sin(Math.tan(x));
45 final Point2D p = new Point2D(x, y);
49 return new Graph(scale, data, "y = sin(tan(x))", location);
52 private static Graph getFormula2Graph(final Point3D location)
54 final List<Point2D> data = new ArrayList<>();
55 for (double x = 0; x < 20; x += 0.25) {
56 final double y = (Math.pow((10 - x), 2) / 30) - 2;
58 final Point2D p = new Point2D(x, y);
62 return new Graph(scale, data, "y = ( (10-x)^2 ) / 30", location);
65 private static Graph getFormula3Graph(final Point3D location)
67 final List<Point2D> data = new ArrayList<>();
68 for (double x = 0; x < 20; x += 0.25) {
69 final double y = Math.sin(x / 2) + Math.sin(x / 1.26);
71 final Point2D p = new Point2D(x, y);
75 return new Graph(scale, data, "y = sin(x/2) + sin(x/1.26)", location);
78 private static Graph getSinusGraph(final Point3D location)
80 final List<Point2D> data = new ArrayList<>();
81 for (double x = 0; x < 20; x += 0.25) {
82 final double y = Math.sin(x);
84 final Point2D p = new Point2D(x, y);
88 return new Graph(scale, data, "Sinus", location);
91 private static Graph getTangentGraph(final Point3D location)
93 final List<Point2D> data = new ArrayList<>();
94 for (double x = 0; x < 20; x += 0.25) {
95 double y = Math.tan(x);
102 final Point2D p = new Point2D(x, y);
106 return new Graph(scale, data, "Tangent", location);
109 public static void main(final String[] args) throws IOException {
111 final ViewFrame viewFrame = new ViewFrame();
113 final ShapeCollection geometryCollection = viewFrame.getView()
114 .getContext().getRootShapeCollection();
116 Point3D location = new Point3D(-600, -300, 0);
117 geometryCollection.addShape(getSinusGraph(location));
119 location = new Point3D(600, -300, 0);
120 geometryCollection.addShape(getFormula1Graph(location));
122 location = new Point3D(-600, 0, 0);
123 geometryCollection.addShape(getCosinusGraph(location));
125 location = new Point3D(600, 0, 0);
126 geometryCollection.addShape(getFormula2Graph(location));
128 location = new Point3D(-600, 300, 0);
129 geometryCollection.addShape(getTangentGraph(location));
131 location = new Point3D(600, 300, 0);
132 geometryCollection.addShape(getFormula3Graph(location));
134 viewFrame.getView().getContext().getAvatar()
135 .setLocation(new Point3D(0, 0, -500));