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)
53 final List<Point2D> data = new ArrayList<>();
54 for (double x = 0; x < 20; x += 0.25) {
55 final double y = (Math.pow((10 - x), 2) / 30) - 2;
57 final Point2D p = new Point2D(x, y);
61 return new Graph(scale, data, "y = ( (10-x)^2 ) / 30", location);
64 private static Graph getFormula3Graph(final Point3D location)
66 final List<Point2D> data = new ArrayList<>();
67 for (double x = 0; x < 20; x += 0.25) {
68 final double y = Math.sin(x / 2) + Math.sin(x / 1.26);
70 final Point2D p = new Point2D(x, y);
74 return new Graph(scale, data, "y = sin(x/2) + sin(x/1.26)", location);
77 private static Graph getSineGraph(final Point3D location)
79 final List<Point2D> data = new ArrayList<>();
80 for (double x = 0; x < 20; x += 0.25) {
81 final double y = Math.sin(x);
83 final Point2D p = new Point2D(x, y);
87 return new Graph(scale, data, "Sine", location);
90 private static Graph getTangentGraph(final Point3D location)
92 final List<Point2D> data = new ArrayList<>();
93 for (double x = 0; x < 20; x += 0.25) {
94 double y = Math.tan(x);
101 final Point2D p = new Point2D(x, y);
105 return new Graph(scale, data, "Tangent", location);
108 public static void main(final String[] args) throws IOException {
110 final ViewFrame viewFrame = new ViewFrame();
112 final ShapeCollection geometryCollection = viewFrame.getViewPanel()
113 .getRootShapeCollection();
115 Point3D location = new Point3D(-600, -300, 0);
116 geometryCollection.addShape(getSineGraph(location));
118 location = new Point3D(600, -300, 0);
119 geometryCollection.addShape(getFormula1Graph(location));
121 location = new Point3D(-600, 0, 0);
122 geometryCollection.addShape(getCosineGraph(location));
124 location = new Point3D(600, 0, 0);
125 geometryCollection.addShape(getFormula2Graph(location));
127 location = new Point3D(-600, 300, 0);
128 geometryCollection.addShape(getTangentGraph(location));
130 location = new Point3D(600, 300, 0);
131 geometryCollection.addShape(getFormula3Graph(location));
133 viewFrame.getViewPanel().getAvatar()
134 .setLocation(new Point3D(0, 0, -500));