Hi,
There is no such method in Java to test this. But have a look at the
Polygon and the Line2D class. The Polygon class implements a
contains(Point2D) and the Line2D implements a intersects(Line2D) method.
The general way of determining if a Line is contained in a Polygon is to
check if the Polygon contains the start and end points of the line and
if the line does not intersect any of the lines of the Polygon. Hope
that is right and understandable since I dealt with this years ago :)
Cheers, Mathias
-----Ursprüngliche Nachricht-----
Von: owner-visad-list@xxxxxxxxxxxxx
[mailto:owner-visad-list@xxxxxxxxxxxxx] Im Auftrag von Tan Ka Ju
Gesendet: Freitag, 25. Juli 2003 10:21
An: 'Ugo Taddei'; 'Rakesh Rathod'
Betreff: RE: printing three display components
Hello.
Is their in Java any method to know is a line contains or inside an
arbitrary polygon or shape? Or is the any algorithm or mathematics
formula that can solve this problem?
Thanks.
KJ
-----Original Message-----
From: owner-visad-list@xxxxxxxxxxxxx
[mailto:owner-visad-list@xxxxxxxxxxxxx] On Behalf Of Ugo Taddei
Sent: Friday, July 25, 2003 3:47 PM
To: Rakesh Rathod
Subject: Re: printing three display components
Hello,
Curtis Rueden wrote:
> Hi Rakesh,
>
> I don't know that much about printing in Java, but looking at
> the DisplayImpl.getPrintable() method, it appears you could
> construct a Printable object in whose print() method you create
> a BufferedImage consisting of a synthesis of the three displays
> (in whatever orientation you desire). Use DisplayImpl.getImage()
> to grab a BufferedImage with the contents of a VisAD Display.
> See DisplayImpl.getPrintable() for an example of using the
> Printable interface to send BufferedImages to the printer.
>
> There could be an easier way, but that's really more of a Java
> programming question, rather than a VisAD question.
Definitely a Java programming question. Nevertheless, I found code
snippet lying around on my disk. Feel free to try it (I don't even now
if it works; it might have worked, some time ago ;-) then let us know
when you improved it.
NB: Follow Curtis' suggestions, and you'll also need to change
final JPanel gp = this.getCentralPanel();
to match the panel where all your displays live.
public Printable getPrintable()
{
Printable printer=null;
final JPanel gp = this.getCentralPanel();
if (printer == null)
printer
new Printable() {
public int print(Graphics g, PageFormat pf, int pi)
throws PrinterException
{
if (pi >= 1)
{
return Printable.NO_SUCH_PAGE;
}
pf.setOrientation(PageFormat.LANDSCAPE);
// or: LANDSCAPE
//JPanel gp = getcentralPanel();
Image image = (Image) gp.createImage(gp.getWidth ()
,gp.getHeight());
Graphics gg = image.getGraphics();
gp.paint(gg);
BufferedImage bufImage = (BufferedImage)image;
//BufferedImage image = DisplayImpl.this.getImage();
g.drawImage(
bufImage,
(int) pf.getImageableX(),
(int) pf.getImageableY(),
gp);
return Printable.PAGE_EXISTS;
}
};
return printer;
}
Cheers,
Ugo