プログラマメモ2 - programmer no memo2

下に見える箱、一点透視図法 2008/05/17

目の高さ(アイレベル)が上のときに場合の一点透視です。
消失点が上にきます。




Javaです。
下記コード
package pers;

import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Test {

static class Panel extends JPanel {

@Override
protected void paintComponent(Graphics g) {

Graphics2D g2d = (Graphics2D) g;
// vanishing point
Point vp = new Point(0, 100);
int w = 100;
int h = 100;

int x = 500;
int y = 500;

float dash[] = { 10.0f, 3.0f };
BasicStroke dashStroke = new BasicStroke(1.0f,
BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3.0f, dash,
0.0f);
BasicStroke stroke = new BasicStroke(1.f);
g2d.setStroke(stroke);
g2d.drawRect(x, y, w, h);
g2d.setStroke(dashStroke);

g2d.drawLine(vp.x, vp.y, x, y);
g2d.drawLine(vp.x, vp.y, x + w, y + h);
g2d.drawLine(vp.x, vp.y, x + w, y);
g2d.drawLine(vp.x, vp.y, x, y + h);

}

}

public static void main(String[] args) {

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new Panel());
frame.setVisible(true);

}

}

: