нужно дописать программу. у меня неправильно определяет принадлежность точек - вопрос №1078106

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class lab7 extends Applet implements Runnable, KeyListener, ActionListener{
public int w=1500;
public int h=800;
public double xB[]={6.5, -6.5, -6.5, 6.5};
public double yB[]={6.5, 6.5, -6.5, -6.5};

public double xN1[]=new double[xB.length];
public double yN1[]=new double[yB.length];

public int xN2[]=new int[xB.length];
public int yN2[]=new int[yB.length];


public double xM[][]={{1.5, -1.5,-1.5, 1.5},
{1.5, -1.5, -1.5, 1.5},
{1.5, -1.5, -1.5, 1.5},
{5.5, 2.5, 2.5, 5.5},
{-2.5, -5.5, -5.5, -2.5}};
public double yM[][]={{1.5, 1.5, -1.5, -1.5},
{-2.5, -2.5, -5.5, -5.5},
{5.5, 5.5, 2.5, 2.5},
{1.5, 1.5, -1.5, -1.5},
{1.5, 1.5, -1.5, -1.5}};

public double xE[]={-2.0, 3.5, -1.0, 8.0, -4.0, 2.0, 5.0, 6.5};
public double yE[]={ 7.0, 3.5, -6.5, 5.5, -3.5, 2.0, 4.0, -4.0};

public double x0=0;
public double y0=0;
public double alpha=20,step=1;

public Image buff=null;
public Thread th=null;

public boolean b=false;

Font f1=new Font(«Arial», Font.PLAIN,20);
Font f2=new Font(«Arial», Font.PLAIN,17);
Font f3=new Font(«Arial», Font.PLAIN,10);


public void init() {
Panel p=new Panel();
setLayout (new FlowLayout (FlowLayout.LEFT, 900, 500));
Button knopka1=new Button(«По часовой стрелке»);
knopka1.addActionListener(this);
p.add(knopka1);
Button knopka2=new Button(«Против часовой стрелки»);
knopka2.addActionListener(this);
p.add(knopka2);
Button knopka3=new Button(«Стоп»);
knopka3.addActionListener(this);
p.add(knopka3);
add(p);
addKeyListener(this);
}

public boolean find(double xB, double yB){
double ax=Math.abs(xB), ay=Math.abs(yB);
if (ax<=5&&ay<=5)
if (Math.pow(ax-2.5, 2)+Math.pow(ay-2.5,2)>=6.25) return true;
else return false;

else return false;
}



public void paint(Graphics gr) {

requestFocus();

buff = createImage(w,h);
Graphics g = buff.getGraphics();

g.setColor(Color.black);
double xEN[]=new double[xE.length];
double yEN[]=new double[yE.length];
int x[]=new int[4];
int y[]=new int[4];

int x5[][]=new int [5][4];
int y5[][]=new int [5][4];

for (int i=0; i<4; i++){
x[i]=500+(int)Math.round(40*(xB[i]*Math.cos(alpha/180.0*Math.PI)-yB[i]*Math.sin(alpha/180.0*Math.PI)));
y[i]=400-(int)Math.round(40*(xB[i]*Math.sin(alpha/180.0*Math.PI)+yB[i]*Math.cos(alpha/180.0*Math.PI)));
}
g.fillPolygon(x, y, 4);


for (int k=0; k<5; k++) {
for (int i=0; i<4; i++){
x5[k][i]=500+(int)Math.round(40*(xM[k][i]*Math.cos(alpha/180.0*Math.PI)-yM[k][i]*Math.sin(alpha/180.0*Math.PI)));
y5[k][i]=400-(int)Math.round(40*(xM[k][i]*Math.sin(alpha/180.0*Math.PI)+yM[k][i]*Math.cos(alpha/180.0*Math.PI)));
}
g.setColor(Color.white);
g.fillPolygon(x5[k], y5[k], 4);
}



g.setXORMode(Color.white);

g.setColor(Color.black);
for (int i=0; i<8; i++) {
g.fillOval(500-(int)Math.round(40*(-xE[i]))-3,
400-(int)Math.round(40*(yE[i]))-3,
6, 6);
g.drawString(Integer.toString(i+1),
500-(int)Math.round(40*(-xE[i])),
400-(int)Math.round(40*(yE[i])));
}

Font f1=new Font(«Arial», Font.PLAIN, 20);
g.setColor(new Color(50, 100, 200));
g.drawLine(480, 40+37, 500, 20+37);
g.drawLine(520, 40+37, 500, 20+37);


g.drawLine(960, 380, 980, 400);
g.drawLine(960, 420, 980, 400);

g.drawLine(20, 400, 980, 400);

for (int i=-11; i<=11; i++)
if (i!=0){
g.drawLine(500+40*i, 395, 500+40*i, 405);
g.drawString(Integer.toString(i), 495+40*i,425);
}

g.drawLine(500, 60, 500, 750);
for (int j=-8; j<=8; j++)
if (j!=0){
g.drawLine(496, 400-40*j, 504,400-40*j);
g.drawString(Integer.toString(j), 512,400-40*j);

}

g.setFont(f1);
g.drawString(«0», 505, 425);
g.drawString («x», 980, 425);
g.drawString(«y»,525,60);
g.setPaintMode();

for (int i=0;i<8;i++){
xEN[i]=xE[i]*Math.cos(alpha/180.0*Math.PI)-yE[i]*Math.sin(alpha/180.0*Math.PI);
yEN[i]=xE[i]*Math.sin(alpha/180.0*Math.PI)+yE[i]*Math.cos(alpha/180.0*Math.PI);
if(find(xEN[i],yEN[i])) g.drawString(«yes», 1080, 100+(i+1)*29);
else g.drawString(«no»,1080, 100+(i+1)*29);
}


//таблица
//1 колонка
for (int i=0; i<=9; i++){
if ( i!=0)
g.drawRect(880, 50+29*i, 50, 30);
}
g.setFont(f2);
g.drawString(«i»,903,100);
for (int i=0; i<=8; i++){
if (i!=0)
g.drawString(Integer.toString(i),903,102+29*i);
}


//2 колонка
for (int i=0; i<=9; i++)
if ( i!=0){
g.drawRect(930,50+29*i, 50, 30);
}
g.drawString(«x»,953,100);
g.setFont(f3);
g.drawString(«i»,960,105);
g.setFont(f2);
for (int i=0; i<9; i++){
if (i!=0)
g.drawString(Double.toString(xE[i-1]), 945, 102+29*i);
}

//3 колонка
for (int i=0; i<=9; i++)
if ( i!=0){
g.drawRect(980,50+29*i, 50, 30);
}
g.setFont(f2);
g.drawString(«y»,1003,100);
g.setFont(f3);
g.drawString(«i»,1010,105);

g.setFont(f2);
for (int i=0; i<9; i++){
if (i!=0)
g.drawString(Double.toString(yE[i-1]), 995, 102+29*i);
}
//4 колонка
for (int i=0; i<=9; i++)
if ( i!=0){
g.drawRect(1030,50+29*i, 140, 30);
g.drawString(«принадлежность »,1035,100);
}

gr.drawImage(buff, 0, 0, null);
}
public void update(Graphics gr) {
paint(gr);
}
public void run() {
while(b){
try{
th.sleep(1);
alpha+=step;
for(int i=0;i<xB.length;i++){
xN1[i]=xB[i]*Math.cos(alpha*Math.PI/180)+yB[i]*Math.sin(alpha*Math.PI/180);
yN1[i]=-xB[i]*Math.sin(alpha*Math.PI/180)+yB[i]*Math.cos(alpha*Math.PI/180);
xN2[i]=240+(int)Math.round(15*xN1[i]);
yN2[i]=240-(int)Math.round(15*yN1[i]);
}
repaint();
} catch (InterruptedException e){}
}

}
public void keyPressed(KeyEvent e) {
int m=e.getKeyCode();
if (m==e.VK_ESCAPE){
step=0;
if (!b){
th=new Thread(this); b=false;
th.stop();
}
}
else if (m==e.VK_ENTER){
alpha=0;
if (!b){
th=new Thread(this); b=true;
th.start();
}
}
else if (m==e.VK_UP) step-=1.0;
else if (m==e.VK_DOWN) step+=1.0;

}
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub

}
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub

}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(«По часовой стрелке»)){
alpha=0;
if (!b){
th=new Thread(this); b=true;
th.start();
}
if (step<0) step=-step;
}
else if(e.getActionCommand().equals(«Против часовой стрелки»)){
alpha=0;
if (!b){
th=new Thread(this); b=true;
th.start();
}
if (step>=0) step=-step;
}
else if(e.getActionCommand().equals(«Стоп»)){
step=0;
if (!b){
th=new Thread(this); b=false;
th.stop();
}
//if (step>=0) step=-step;
}
//repaint();
}
}

Ответы

метод main в applet — Java SEhttp://www.cyberforum.ru/java-j2se/thread309836.html
04.11.16
Посмотреть всех экспертов из раздела Технологии > Java/J2EE
Пользуйтесь нашим приложением Доступно на Google Play Загрузите в App Store