2 * Sixth 3D engine demos. Copyright ©2012-2019, 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) {
26 final List<Point2D> data = new ArrayList<>();
27 for (double x = 0; x < 20; x += 0.25) {
28 final double y = Math.cos(x);
30 final Point2D p = new Point2D(x, y);
34 return new Graph(scale, data, "Cosine", location);
37 private static Graph getFormula1Graph(final Point3D location) {
38 final List<Point2D> data = new ArrayList<>();
39 for (double x = 0; x < 20; x += 0.25) {
40 final double y = Math.sin(Math.tan(x));
42 final Point2D p = new Point2D(x, y);
46 return new Graph(scale, data, "y = sin(tan(x))", location);
49 private static Graph getFormula2Graph(final Point3D location) {
50 final List<Point2D> data = new ArrayList<>();
51 for (double x = 0; x < 20; x += 0.25) {
52 final double y = (Math.pow((10 - x), 2) / 30) - 2;
54 final Point2D p = new Point2D(x, y);
58 return new Graph(scale, data, "y = ( (10-x)^2 ) / 30", location);
61 private static Graph getFormula3Graph(final Point3D location) {
62 final List<Point2D> data = new ArrayList<>();
63 for (double x = 0; x < 20; x += 0.25) {
64 final double y = Math.sin(x / 2) + Math.sin(x / 1.26);
66 final Point2D p = new Point2D(x, y);
70 return new Graph(scale, data, "y = sin(x/2) + sin(x/1.26)", location);
73 private static Graph getSineGraph(final Point3D location) {
74 final List<Point2D> data = new ArrayList<>();
75 for (double x = 0; x < 20; x += 0.25) {
76 final double y = Math.sin(x);
78 final Point2D p = new Point2D(x, y);
82 return new Graph(scale, data, "Sine", location);
85 private static Graph getTangentGraph(final Point3D location) {
86 final List<Point2D> data = new ArrayList<>();
87 for (double x = 0; x < 20; x += 0.25) {
88 double y = Math.tan(x);
95 final Point2D p = new Point2D(x, y);
99 return new Graph(scale, data, "Tangent", location);
102 public static void main(final String[] args) throws IOException {
104 final ViewFrame viewFrame = new ViewFrame();
106 final ShapeCollection geometryCollection = viewFrame.getViewPanel()
107 .getRootShapeCollection();
109 Point3D location = new Point3D(-600, -300, 0);
110 geometryCollection.addShape(getSineGraph(location));
112 location = new Point3D(600, -300, 0);
113 geometryCollection.addShape(getFormula1Graph(location));
115 location = new Point3D(-600, 0, 0);
116 geometryCollection.addShape(getCosineGraph(location));
118 location = new Point3D(600, 0, 0);
119 geometryCollection.addShape(getFormula2Graph(location));
121 location = new Point3D(-600, 300, 0);
122 geometryCollection.addShape(getTangentGraph(location));
124 location = new Point3D(600, 300, 0);
125 geometryCollection.addShape(getFormula3Graph(location));
127 viewFrame.getViewPanel().getAvatar()
128 .setLocation(new Point3D(0, 0, -500));