|
| 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 | +} |
0 commit comments