2 * Sixth 3D engine demos. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
9 package eu.svjatoslav.sixth.e3d.examples;
11 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.Graph;
17 import java.io.IOException;
18 import java.util.ArrayList;
19 import java.util.List;
21 public class GraphDemo {
23 private static final double scale = 50d;
25 private static Graph getCosineGraph(final Point3D location)
27 final List<Point2D> data = new ArrayList<>();
28 for (double x = 0; x < 20; x += 0.25) {
29 final double y = Math.cos(x);
31 final Point2D p = new Point2D(x, y);
35 return new Graph(scale, data, "Cosine", location);
38 private static Graph getFormula1Graph(final Point3D location)
40 final List<Point2D> data = new ArrayList<>();
41 for (double x = 0; x < 20; x += 0.25) {
42 final double y = Math.sin(Math.tan(x));
44 final Point2D p = new Point2D(x, y);
48 return new Graph(scale, data, "y = sin(tan(x))", location);
51 private static Graph getFormula2Graph(final Point3D location) {
52 final List<Point2D> data = new ArrayList<>();
53 for (double x = 0; x < 20; x += 0.25) {
54 final double y = (Math.pow((10 - x), 2) / 30) - 2;
56 final Point2D p = new Point2D(x, y);
60 return new Graph(scale, data, "y = ( (10-x)^2 ) / 30", location);
63 private static Graph getFormula3Graph(final Point3D location)
65 final List<Point2D> data = new ArrayList<>();
66 for (double x = 0; x < 20; x += 0.25) {
67 final double y = Math.sin(x / 2) + Math.sin(x / 1.26);
69 final Point2D p = new Point2D(x, y);
73 return new Graph(scale, data, "y = sin(x/2) + sin(x/1.26)", location);
76 private static Graph getSineGraph(final Point3D location)
78 final List<Point2D> data = new ArrayList<>();
79 for (double x = 0; x < 20; x += 0.25) {
80 final double y = Math.sin(x);
82 final Point2D p = new Point2D(x, y);
86 return new Graph(scale, data, "Sine", location);
89 private static Graph getTangentGraph(final Point3D location)
91 final List<Point2D> data = new ArrayList<>();
92 for (double x = 0; x < 20; x += 0.25) {
93 double y = Math.tan(x);
100 final Point2D p = new Point2D(x, y);
104 return new Graph(scale, data, "Tangent", location);
107 public static void main(final String[] args) throws IOException {
109 final ViewFrame viewFrame = new ViewFrame();
111 final ShapeCollection geometryCollection = viewFrame.getViewPanel()
112 .getRootShapeCollection();
114 Point3D location = new Point3D(-600, -300, 0);
115 geometryCollection.addShape(getSineGraph(location));
117 location = new Point3D(600, -300, 0);
118 geometryCollection.addShape(getFormula1Graph(location));
120 location = new Point3D(-600, 0, 0);
121 geometryCollection.addShape(getCosineGraph(location));
123 location = new Point3D(600, 0, 0);
124 geometryCollection.addShape(getFormula2Graph(location));
126 location = new Point3D(-600, 300, 0);
127 geometryCollection.addShape(getTangentGraph(location));
129 location = new Point3D(600, 300, 0);
130 geometryCollection.addShape(getFormula3Graph(location));
132 viewFrame.getViewPanel().getAvatar()
133 .setLocation(new Point3D(0, 0, -500));