2 * Sixth 3D engine demos. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
7 package eu.svjatoslav.sixth.e3d.examples;
9 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
10 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
11 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
12 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.Graph;
15 import java.io.IOException;
16 import java.util.ArrayList;
17 import java.util.List;
19 public class GraphDemo {
21 private static final double scale = 50d;
23 private static Graph getCosineGraph(final Point3D location) {
24 final List<Point2D> data = new ArrayList<>();
25 for (double x = 0; x < 20; x += 0.25) {
26 final double y = Math.cos(x);
28 final Point2D p = new Point2D(x, y);
32 return new Graph(scale, data, "Cosine", location);
35 private static Graph getFormula1Graph(final Point3D location) {
36 final List<Point2D> data = new ArrayList<>();
37 for (double x = 0; x < 20; x += 0.25) {
38 final double y = Math.sin(Math.tan(x));
40 final Point2D p = new Point2D(x, y);
44 return new Graph(scale, data, "y = sin(tan(x))", location);
47 private static Graph getFormula2Graph(final Point3D location) {
48 final List<Point2D> data = new ArrayList<>();
49 for (double x = 0; x < 20; x += 0.25) {
50 final double y = (Math.pow((10 - x), 2) / 30) - 2;
52 final Point2D p = new Point2D(x, y);
56 return new Graph(scale, data, "y = ( (10-x)^2 ) / 30", location);
59 private static Graph getFormula3Graph(final Point3D location) {
60 final List<Point2D> data = new ArrayList<>();
61 for (double x = 0; x < 20; x += 0.25) {
62 final double y = Math.sin(x / 2) + Math.sin(x / 1.26);
64 final Point2D p = new Point2D(x, y);
68 return new Graph(scale, data, "y = sin(x/2) + sin(x/1.26)", location);
71 private static Graph getSineGraph(final Point3D location) {
72 final List<Point2D> data = new ArrayList<>();
73 for (double x = 0; x < 20; x += 0.25) {
74 final double y = Math.sin(x);
76 final Point2D p = new Point2D(x, y);
80 return new Graph(scale, data, "Sine", location);
83 private static Graph getTangentGraph(final Point3D location) {
84 final List<Point2D> data = new ArrayList<>();
85 for (double x = 0; x < 20; x += 0.25) {
86 double y = Math.tan(x);
93 final Point2D p = new Point2D(x, y);
97 return new Graph(scale, data, "Tangent", location);
100 public static void main(final String[] args) throws IOException {
102 final ViewFrame viewFrame = new ViewFrame();
104 final ShapeCollection geometryCollection = viewFrame.getViewPanel()
105 .getRootShapeCollection();
107 Point3D location = new Point3D(-600, -300, 0);
108 geometryCollection.addShape(getSineGraph(location));
110 location = new Point3D(600, -300, 0);
111 geometryCollection.addShape(getFormula1Graph(location));
113 location = new Point3D(-600, 0, 0);
114 geometryCollection.addShape(getCosineGraph(location));
116 location = new Point3D(600, 0, 0);
117 geometryCollection.addShape(getFormula2Graph(location));
119 location = new Point3D(-600, 300, 0);
120 geometryCollection.addShape(getTangentGraph(location));
122 location = new Point3D(600, 300, 0);
123 geometryCollection.addShape(getFormula3Graph(location));
125 viewFrame.getViewPanel().getAvatar()
126 .setLocation(new Point3D(0, 0, -500));