Skip to content

Commit a0fdf08

Browse files
authored
Add files via upload
1 parent 823c331 commit a0fdf08

5 files changed

Lines changed: 653 additions & 0 deletions

File tree

Arrow.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import java.awt.*;
2+
import java.awt.geom.Point2D;
3+
4+
public class Arrow
5+
{
6+
double angle;
7+
double coordX;
8+
double coordY;
9+
double screenX;
10+
double screenY;
11+
double length = 3;
12+
Color color;
13+
double magnitude;
14+
double maxCX;
15+
double maxCY;
16+
double maxSX;
17+
double maxSY;
18+
double curl;
19+
double divergence;
20+
Panel panel;
21+
double DPDX;
22+
double DPDY;
23+
double DPDT;
24+
double DQDX;
25+
double DQDY;
26+
double DQDT;
27+
public Arrow(double initX, double initY, Panel panelInit)
28+
{
29+
panel = panelInit;
30+
coordX = initX;
31+
coordY = initY;
32+
maxSX = panel.window_screenX;
33+
maxSY = panel.window_screenY;
34+
maxCX = panel.window_maxCoordX;
35+
maxCY = panel.window_maxCoordY;
36+
screenX = coordsToScreenX(coordX);
37+
screenY = coordsToScreenY(coordY);
38+
Point2D tempPoint = panel.getVector(coordX, coordY);
39+
magnitude = tempPoint.getX();
40+
angle = tempPoint.getY();
41+
Point2D arrowDX = panel.getVector(coordX + 0.001, coordY);
42+
Point2D arrowDY = panel.getVector(coordX, coordY + 0.001);
43+
DPDX = (arrowDX.getX()*Math.cos(arrowDX.getY()) - magnitude*Math.cos(angle))/0.001;//dP/dx
44+
//System.out.println(arrowDX.toString() + " " + DPDX + " " + arrowInit.toString());
45+
DPDY = (arrowDY.getX()*Math.cos(arrowDY.getY()) - magnitude*Math.cos(angle))/0.001;//dP/dy
46+
DQDX = (arrowDX.getX()*Math.sin(arrowDX.getY()) - magnitude*Math.sin(angle))/0.001;//dQ/dx
47+
DQDY = (arrowDY.getX()*Math.sin(arrowDY.getY()) - magnitude*Math.sin(angle))/0.001;
48+
curl = DQDX - DPDY;
49+
divergence = DQDY + DPDX;
50+
}
51+
public void update(Graphics g, Panel panel)
52+
{
53+
maxCX = panel.window_maxCoordX;
54+
maxCY = panel.window_maxCoordY;
55+
coordX = screenToCoordsX(screenX);
56+
coordY = screenToCoordsY(screenY);
57+
Point2D tempPoint = panel.getVector(coordX, coordY);
58+
magnitude = tempPoint.getX();
59+
curl = panel.getCurl(coordX, coordY);
60+
angle = tempPoint.getY();
61+
panel.vector_to_rgb(this);
62+
int endX = (int)(screenX + 2*length*Math.cos(angle));
63+
int endY = (int)(screenY + 2*length*Math.sin(angle));
64+
/*int leftX = endX - (int)(length*Math.sin(angle));
65+
int leftY = endY + (int)(length*Math.cos(angle));
66+
int rightX = endX + (int)(length*Math.sin(angle));
67+
int rightY = endY - (int)(length*Math.cos(angle));
68+
int topX = endX + (int)(length*Math.cos(angle));
69+
int topY = endY + (int)(length*Math.sin(angle));*/
70+
g.setColor(color);
71+
Graphics2D g2d = (Graphics2D)g;
72+
g2d.setStroke(new BasicStroke(3));
73+
g2d.drawLine((int) screenX, (int)screenY, endX, endY);
74+
g2d.drawPolygon(new int[] {endX - (int)(length*Math.sin(angle)), endX + (int)(length*Math.sin(angle)), endX + (int)(length*Math.cos(angle))},new int[] {endY + (int)(length*Math.cos(angle)), endY - (int)(length*Math.cos(angle)), endY + (int)(length*Math.sin(angle))}, 3);
75+
/*
76+
endX
77+
length = Math.sqrt((end[0]-start[0])**2+(end[1]-start[1])**2)
78+
rotation =np.atan2(end[0]-start[0],end[1]-start[1])
79+
//end = (start[0] + length*np.cos(rotation), start[1] + length*np.sin(rotation))
80+
color ='white'
81+
//print(start)
82+
pygame.draw.line(window,color,(start[0],start[1]),(end[0],end[1]),5)
83+
leftSide =(end[0]-0.2*length*np.sin(rotation),end[1]+0.2*length*np.cos(rotation))
84+
rightSide =(end[0]+0.2*length*np.sin(rotation),end[1]-0.2*length*np.cos(rotation))
85+
top =(end[0]+0.2*length*np.cos(rotation),end[1]+0.2*length*np.sin(rotation))
86+
pygame.draw.polygon(window,
87+
88+
vector_to_rgb(np.pi*rotation/180, length), (leftSide,rightSide,top),0)*/
89+
}
90+
public double screenToCoordsX(double screenX) {return 2*panel.window_maxCoordX*(screenX - maxSX/2)/maxSX;}
91+
public double screenToCoordsY(double screenY) {return -2*panel.window_maxCoordY*(screenY - maxSY/2)/maxSY;}
92+
public double coordsToScreenX(double CX) {return 0.5*CX*maxSX/panel.window_maxCoordX + maxSX/2;}
93+
public double coordsToScreenY(double CY) {return -0.5*CY*maxSY/panel.window_maxCoordY + maxSY/2;}
94+
}

Axes.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import java.awt.*;
2+
import java.math.RoundingMode;
3+
import java.text.DecimalFormat;
4+
5+
public class Axes
6+
{
7+
double maxCX;//max x coord
8+
double maxCY;
9+
double SX;//max x pixel (screen)
10+
double SY;
11+
Panel panel;
12+
double tickDistance = 100;
13+
DecimalFormat df = new DecimalFormat("#.####");
14+
public Axes(Panel panelInit)
15+
{
16+
panel = panelInit;
17+
maxCX = panel.window_maxCoordX;
18+
maxCY = panel.window_maxCoordY;
19+
SX = panel.window_screenX;
20+
SY = panel.window_screenY;
21+
df.setRoundingMode(RoundingMode.CEILING);
22+
}
23+
public void update(Graphics g)
24+
{
25+
g.setColor(Color.white);
26+
g.setFont(new Font("Calibri", Font.BOLD, 15));
27+
g.drawLine(0, (int)(SY/2), (int)SX, (int)(SY/2));//horizontal line
28+
for(double i = 0; i < panel.window_screenX; i += tickDistance)
29+
{
30+
if(i + tickDistance/2 != 0)
31+
{
32+
g.drawLine((int)(i + tickDistance / 2), 440, (int)(i + tickDistance / 2), 460);
33+
String text = String.valueOf(screenToCoordsX(i + tickDistance/2));
34+
g.setColor(Color.black);
35+
g.setFont(new Font("Calibri", Font.BOLD, 18));
36+
g.drawString(text, (int)(i + tickDistance / 2), 470);
37+
g.setFont(new Font("Calibri", Font.PLAIN, 17));
38+
g.setColor(Color.white);
39+
g.drawString(text, (int)(i + tickDistance/2), 470);
40+
}
41+
}
42+
g.drawLine((int)(SX/2), 0, (int)(SX/2), (int)SY);//vertical line
43+
for(double i = 0; i < panel.window_screenY; i += tickDistance)
44+
{
45+
if(screenToCoordsY(i + tickDistance/2) != 0)
46+
{
47+
String text = String.valueOf(screenToCoordsY(i + tickDistance/2));
48+
g.setColor(Color.black);
49+
g.setFont(new Font("Calibri", Font.BOLD, 18));
50+
g.drawString(text, 820, (int)(i + tickDistance/2));
51+
g.setFont(new Font("Calibri", Font.PLAIN, 17));
52+
g.setColor(Color.white);
53+
g.drawLine(790, (int)(i + tickDistance / 2), 810, (int)(i + tickDistance / 2));
54+
g.drawString(text, 820, (int)(i + tickDistance/2));
55+
}
56+
}
57+
}
58+
public double screenToCoordsX(double screenX) {return Double.parseDouble(df.format(2*panel.window_maxCoordX*(screenX - panel.window_screenX/2)/panel.window_screenX));}
59+
public double screenToCoordsY(double screenY) {return Double.parseDouble(df.format(-2*panel.window_maxCoordY*(screenY - panel.window_screenY/2)/panel.window_screenY));}
60+
public double coordsToScreenX(double coordX) {return coordX*panel.window_screenX/maxCX;}
61+
public double coordsToScreenY(double coordY) {return coordY*panel.window_screenY/maxCY;}
62+
}

0 commit comments

Comments
 (0)