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]
# 1
I would try an AffineTransform scaleInstance to scale up the GeneralPath to the desired size. You can create a new Shape (which can be cast to a GeneralPath) with the createTransformedShape method found in both the GeneralPath and AffineTransform classes.
crwooda at 2007-7-8 2:06:47 > top of Java-index,Security,Cryptography...
# 2

Hi,

thanks for the answer but I don't think that an affine transformation will solve my problem. Here a little example for one of my generalpaths. Imagine two rooms with a desk in each and a corridor connecting the two rooms. Now what I need is distance of e.g. 25 pixel from every wall and around every obstacle. An that's why I think that an affine transformation won't solve my problem. Every obstacle or internal wall will shrink in this process :-(

Yours

Andr?

Camelmana at 2007-7-8 2:06:47 > top of Java-index,Security,Cryptography...
# 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()));

}

};

}

crwooda at 2007-7-8 2:06:47 > top of Java-index,Security,Cryptography...