Is a dilatation of a generalpath possible?
Hi,
I've got a generalpath that represents the inner contour of a floor plan. Interior like tables are also represented in this generalpath. It's the base for a little simulation program where persons should walk around. Now I'm looking for a way to create a dilatation (e.g. 25 pixel) of the objects and walls that i only need to simulate a single point moving around without paying attention to collide with door frames, tables, etc..
Is there a way to do this? I hope my problem is understandable.
Sincerely yours
Andr?
[558 byte] By [
Camelmana] at [2007-11-26 14:16:37]

# 3
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class Dilatation extends JPanel {
GeneralPath rooms;
JLabel xLabel;
JLabel yLabel;
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if(rooms == null) initRooms();
g2.setPaint(Color.blue);
g2.draw(rooms);
Rectangle r = rooms.getBounds();
double x = r.getCenterX();
double y = r.getCenterY();
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.scale(3.0, 3.0);
at.translate(5, -30);
g2.draw(at.createTransformedShape(rooms));
}
private void initRooms() {
rooms = new GeneralPath();
rooms.moveTo(25,25);
rooms.lineTo(125,25);
rooms.lineTo(125,135);
rooms.lineTo(25,135);
rooms.lineTo(25,25);
rooms.moveTo(75,25);
rooms.lineTo(75,115);
rooms.moveTo(75,125);
rooms.lineTo(75,135);
rooms.moveTo(40,50);
rooms.lineTo(65,50);
rooms.lineTo(65,85);
rooms.lineTo(40,85);
rooms.lineTo(40,50);
rooms.moveTo(85,60);
rooms.lineTo(110,60);
rooms.lineTo(110,95);
rooms.lineTo(85,95);
rooms.lineTo(85,60);
}
public static void main(String[] args) {
Dilatation test = new Dilatation();
test.addMouseMotionListener(test.pointer);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(test);
f.getContentPane().add(test.getLabel(), "Last");
f.setSize(500,500);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
private JPanel getLabel() {
xLabel = new JLabel();
yLabel = new JLabel();
Dimension d = new Dimension(45,25);
JPanel panel = new JPanel(new GridBagLayout());
panel.setBorder(BorderFactory.createEtchedBorder());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(1,1,1,1);
addComponents(new JLabel("x ="), xLabel, panel, d, gbc, true);
addComponents(new JLabel("y ="), yLabel, panel, d, gbc, false);
return panel;
}
private void addComponents(JComponent c1, JComponent c2, Container c,
Dimension d, GridBagConstraints gbc, boolean b) {
gbc.anchor = gbc.EAST;
gbc.weightx = b ? 1.0 : 0;
c.add(c1, gbc);
c2.setPreferredSize(d);
//c2.setBorder(BorderFactory.createEtchedBorder());
gbc.anchor = gbc.WEST;
gbc.weightx = b ? 0 : 1.0;
c.add(c2, gbc);
}
private MouseMotionListener pointer = new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
xLabel.setText(String.valueOf(e.getX()));
yLabel.setText(String.valueOf(e.getY()));
}
};
}