This commit is contained in:
Alex Lin 2017-05-15 13:40:25 -05:00
commit 706e7ff942
10 changed files with 219 additions and 13 deletions

View File

@ -21,6 +21,9 @@ S_sie.resource
S_source.cpp
S_source.hh
T_main_*
trick
**/SIM_*/trick
**/graphics/dist
**/graphics/manifest
**/graphics/build
jitlib
build

View File

@ -1,4 +1,4 @@
#SIM\_cannon\_analytic
# SIM\_cannon\_analytic
---
This is first of eight Trick-based simulations that one builds in the Trick
Tutorial (Section 3). It's purpose is to introduce some of the fundamentals

View File

@ -1,8 +1,8 @@
#SIM\_cannon\_integ
# SIM\_cannon\_integ
![CannonPicture](images/CannonInit.png)
###The Simulation
### The Simulation
This is a simulation of a cannon shooting a cannonball. Given the initial position of the cannon ball, the muzzle velocity (speed) of the cannon ball, and the elevation angle of the cannon barrel the simulation computes the cannon ball's trajectory and time of impact with the ground.
@ -12,4 +12,4 @@ The acceleration of gravity is assumed to be -9.81 m/s<sup>2</sup>.

View File

@ -1,4 +1,4 @@
#SIM_parachute
# SIM_parachute
![Picture of Parachutist](images/Parachutist.png)

View File

@ -1,3 +0,0 @@
build
dist
manifest

View File

@ -0,0 +1,206 @@
/*
* Trick
* 2016 (c) National Aeronautics and Space Administration (NASA)
*/
package trick;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileReader;
import java.net.Socket;
import java.util.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
/**
*
* @author penn
*/
class SkyView extends JPanel {
private double scale; // Pixels per meter
private Color skyColor;
private Color planetColor;
private Color satelliteColor;
private int planetRadius;
private double[] satellitePos;
// Origin of world coordinates in jpanel coordinates.
private int worldOriginX;
private int worldOriginY;
public SkyView( double mapScale ) {
scale = mapScale;
setScale(mapScale);
skyColor = Color.BLACK;
planetColor = new Color(100,200,200);
satelliteColor = new Color(255,0,0);
planetRadius = 6378000;
satellitePos = new double[] {0.0, planetRadius + 200000};
}
public void setSatPos (double x, double y) {
satellitePos[0] = x;
satellitePos[1] = y;
}
public void setScale (double mapScale) {
if (mapScale < 0.00005) {
scale = 0.00005;
} else {
scale = mapScale;
}
}
public void drawCenteredCircle(Graphics2D g, int x, int y, int r) {
x = x-(r/2);
y = y-(r/2);
g.fillOval(x,y,r,r);
}
private void doDrawing(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
int width = getWidth();
int height = getHeight();
worldOriginX = (width/2);
worldOriginY = (height/2);
g2d.setPaint(Color.BLACK);
g2d.fillRect(0, 0, width, height);
// Draw Planet
g2d.setPaint(planetColor);
drawCenteredCircle(g2d, worldOriginX, worldOriginY, (int)(scale * 2 * planetRadius));
// Draw Satellite
g2d.setPaint(satelliteColor);
int sx = (int)(worldOriginX + scale * satellitePos[0]);
int sy = (int)(worldOriginY - scale * satellitePos[1]);
drawCenteredCircle(g2d, sx, sy, (int)(10));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
}
public class SatDisplay extends JFrame {
private SkyView skyView;
private BufferedReader in;
private DataOutputStream out;
public SatDisplay(SkyView sky) {
skyView = sky;
add( skyView);
setTitle("Orbit Display");
setSize(800, 800);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void connectToServer(String host, int port ) throws IOException {
Socket socket = new Socket(host, port);
in = new BufferedReader( new InputStreamReader( socket.getInputStream()));
out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
}
public void drawSkyView() {
skyView.repaint();
}
private static void printHelpText() {
System.out.println(
"----------------------------------------------------------------------\n"
+ "usage: java jar SatDisplay.jar <port-number>\n"
+ "----------------------------------------------------------------------\n"
);
}
public static void main(String[] args) throws IOException {
String host = "localHost";
int port = 0;
String vehicleImageFile = null;
int ii = 0;
while (ii < args.length) {
switch (args[ii]) {
case "-help" :
case "--help" : {
printHelpText();
System.exit(0);
} break;
default : {
port = (Integer.parseInt(args[ii]));
} break;
}
++ii;
}
if (port == 0) {
System.out.println("No variable server port specified.");
printHelpText();
System.exit(0);
}
double mapScale = 0.00005; // 20,000 meters per pixel
SkyView skyview = new SkyView( mapScale);
SatDisplay sd = new SatDisplay(skyview);
sd.setVisible(true);
double satX = 0.0;
double satY = 0.0;
System.out.println("Connecting to: " + host + ":" + port);
sd.connectToServer(host, port);
sd.out.writeBytes("trick.var_set_client_tag(\"SatDisplay\") \n");
sd.out.flush();
sd.out.writeBytes("trick.var_add(\"dyn.satellite.pos[0]\") \n" +
"trick.var_add(\"dyn.satellite.pos[1]\") \n" );
sd.out.flush();
sd.out.writeBytes("trick.var_ascii() \n" +
"trick.var_cycle(0.1) \n" +
"trick.var_send() \n" );
sd.out.flush();
Boolean go = true;
while (go) {
String field[];
try {
String line;
line = sd.in.readLine();
field = line.split("\t");
satX = Double.parseDouble( field[1] );
satY = Double.parseDouble( field[2] );
// Set the Satellite position
skyview.setSatPos(satX, satY);
} catch (IOException | NullPointerException e ) {
go = false;
}
sd.drawSkyView();
}
}
}

View File

@ -42,11 +42,11 @@ sun\_predictor.sun.utc | CALENDAR\_DATE | --
**NOTE:** 0 <= Solar Azimuth < 360 degrees. North = 0, East = 90, South = 180, West = 270.
###Scenarios
### Scenarios
####[RUN_Winter](RUN_Winter/RESULTS.md)
#### [RUN_Winter](RUN_Winter/RESULTS.md)
####[RUN_Summer](RUN_Summer/RESULTS.md)
#### [RUN_Summer](RUN_Summer/RESULTS.md)
### References
Meeus, Jean, (1998) "Astronomical Algorithms", Willmann-Bell, Inc. ISBN 0-943396-61-1.

View File

@ -1,4 +1,4 @@
#SIM\_wheelbot
# SIM\_wheelbot
---