Plotar gráfico

2 respostas
P

Ou, seguinte tem 3 método um que desenha um função seno, coseno e tangente, estou precisando agora fazer o gráfico da secante, cosecante e da cotangente, abaixo segue os códigos

private void drawCos(Graphics2D g2D) {

		g2D.drawString("Sine Wave", 250, 10); // Draw some text
		g2D.drawString(" 100", 15, 95); // Draw some text
		g2D.drawString(" 0", 15, 205); // Draw some text
		g2D.drawString("-100", 15, 305); // Draw some text

		g2D.drawLine(40, 200, 460, 200);

		int old_x = 50;
		int old_y = 50;
		int new_x = 50;
		int new_y = 300;

		for (int i = 1; i <= 100; i++) {

			old_x = new_x;
			old_y = new_y;

			new_x += 4;

			new_y = (int) (((Math.cos(((2 * Math.PI) / 100.0) * i)) * -100) + 200.0);

			System.out.println("From: " + old_x + ", " + old_y + " To: "
					+ new_x + ", " + new_y);

			g2D.drawLine(old_x, old_y, new_x, new_y );
		}

	}

	private void drawSin(Graphics2D g2D) {

		g2D.drawString("Sine Wave", 250, 10); // Draw some text
		g2D.drawString(" 100", 15, 95); // Draw some text
		g2D.drawString(" 0", 15, 205); // Draw some text
		g2D.drawString("-100", 15, 305); // Draw some text

		g2D.drawLine(40, 200, 460, 200);

		int old_x = 50;
		int old_y = 200;
		int new_x = 50;
		int new_y = 200;

		for (int i = 1; i <= 100; i++) {

			old_x = new_x;
			old_y = new_y;

			new_x += 4;

			new_y = (int) (((Math.sin(((2 * Math.PI) / 100.0) * i)) * -100) + 200.0);

			System.out.println("From: " + old_x + ", " + old_y + " To: "
					+ new_x + ", " + new_y);

			g2D.drawLine(old_x, old_y, new_x, new_y);
		}
	}
	
	private void drawTan(Graphics2D g2D){
	
		g2D.drawString("Sine Wave", 250, 10); // Draw some text
		g2D.drawString(" 100", 15, 95); // Draw some text
		g2D.drawString(" 0", 15, 205); // Draw some text
		g2D.drawString("-100", 15, 305); // Draw some text

		g2D.drawLine(40, 200, 460, 200);
		g2D.drawLine(50, 50, 50, 350);

		int old_x = 50;
		int old_y = 200;
		int new_x = 50;
		int new_y = 200;

		for (int i = 1; i <= 100; i++) {

			old_x = new_x;
			old_y = new_y;

			new_x += 4;

			new_y = (int) (((Math.tan(((2 * Math.PI) / 100.0) * i)) * -10) + 200.0);

			System.out.println("From: " + old_x + ", " + old_y + " To: "
					+ new_x + ", " + new_y);

			g2D.drawLine(old_x, old_y, new_x, new_y);
		}
	
	}

Alguem tem alguma ideia de como posso fazer ??

2 Respostas

jmoreira

Putz… disciplina de calculo?
Cara, dê uma olha por aqui. Você vai encontrar bastante códigos exemplos.

P

Cara até já consegui fazer isso, eu sabia o conceito mas apliquei errado, na verdade é simples pois secante é 1 sobre cosseno, e cossecante é 1 sobre seno, já resolve.

Criado 27 de março de 2008
Ultima resposta 30 de mar. de 2008
Respostas 2
Participantes 2