Rev | Line | |
---|
[267] | 1 | package onetomany.etc;
|
---|
[263] | 2 |
|
---|
| 3 | import java.awt.Canvas;
|
---|
| 4 | import java.awt.Color;
|
---|
| 5 | import java.awt.Graphics;
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * @author Faria Nassiri-Mofakham
|
---|
| 10 | *
|
---|
| 11 | */
|
---|
| 12 | public class Paraboloid extends Canvas{
|
---|
| 13 |
|
---|
| 14 | /**
|
---|
| 15 | *
|
---|
| 16 | */
|
---|
| 17 | private static final long serialVersionUID = 1L;
|
---|
| 18 |
|
---|
| 19 | Color color;
|
---|
| 20 | int length;
|
---|
| 21 | double a,b,c;//,d;
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | public Paraboloid(Color col, int l, double aa, double bb, double cc)//, double dd)
|
---|
| 25 | {
|
---|
| 26 | color=col;
|
---|
| 27 | length=l;
|
---|
| 28 | a=aa;
|
---|
| 29 | b=bb;
|
---|
| 30 | c=cc;
|
---|
| 31 | // ?d=dd;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public void paint(Graphics g)
|
---|
| 35 | {
|
---|
| 36 | g.setColor(color);
|
---|
| 37 | g.drawLine(g.getClipBounds().x,g.getClipBounds().y, g.getClipBounds().x+length,g.getClipBounds().y);
|
---|
| 38 |
|
---|
| 39 | g.setColor(Color.red);
|
---|
| 40 | for (double x=-100;x<=100;x = x+0.1){
|
---|
| 41 | double y = a * x * x + b * x + c;
|
---|
| 42 | int X = (int)Math.round(200 + x*20);
|
---|
| 43 | int Y = (int)Math.round(200 - y*20);
|
---|
| 44 | g.fillOval(X-2,Y-2,4,4);
|
---|
| 45 |
|
---|
| 46 | y = - (x + 4) * (x + 4) - 7;
|
---|
| 47 | X = (int)Math.round(200 + x*20);
|
---|
| 48 | Y = (int)Math.round(200 - y*20);
|
---|
| 49 | g.fillOval(X-2,Y-2,4,4);
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | // for (double x=-100;x<=100;x = x+0.1){
|
---|
| 53 | // double z = a * x * x * x + b * x * x + c;
|
---|
| 54 | //
|
---|
| 55 | // double y = a * x * x + b * x + c;
|
---|
| 56 | // int X = (int)Math.round(200 + x*20);
|
---|
| 57 | // int Y = (int)Math.round(200 - y*20);
|
---|
| 58 | // g.fillOval(X-2,Y-2,4,4);
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.