Get the outer border of the unordered point of polygon

Hi all,
I meet some problem regarding about polygon with unordered points of polygon. I got some Point of polygon from source data (ENC file format) that cannot be changed. So, i want to look some help from you all. how to get the outer border of polygon?
Here is the paint function that i had created :
public void paint(Graphics g) {
        super.paint(g);
        Polygon p = new Polygon();
        String point = "3331,2305;3317,2332;3317,2356;3310,2356;3302,2355;3331,2305;3317,2286;3317,2281;3392,2281;3392,2356;3317,2356;"
+                             "3317,2332;3331,2305;3303,2278;3312,2281;3317,2281;3317,2286;3303,2278;3254,2313;3249,2309;3249,2281;"+
                             "3295,2281;3303,2278;3295,2281;3249,2281;3242,2241;3242,2206;3317,2206;3317,2281;3312,2281;3249,2309;"
+                             "3233,2159;3344,2079;3317,2102;3317,2131;3275,2131;3242,2156;3242,2206;3242,2241;3249,2281;3344,2079;"+
                             "3349,2078;3352,2074;3361,2093;3385,2078;3392,2078;3392,2131;3317,2131;3317,2102;3344,2079;3352,2074;"
+                             "3349,2078;3361,2093;3390,2070;3650,2070;3656,2078;3617,2078;3542,2078;3467,2078;3392,2078;3385,2078;"+
                             "3650,2070;3731,2143;3722,2141;3714,2131;3620,2131;3617,2131;3617,2078;3656,2078;3731,2143;3565,2249;"
+                             "3617,2211;3617,2206;3624,2206;3620,2131;3714,2131;3722,2141;3565,2249;3494,2296;3513,2281;3467,2281;"+
                             "3467,2206;3542,2206;3542,2261;3565,2249;3542,2261;3542,2206;3617,2206;3617,2211;3494,2296;3465,2315;"
+                             "3467,2310;3467,2281;3513,2281;3465,2315;3390,2365;3313,2365;3302,2355;3310,2356;3317,2356;3392,2356;"+
                             "3398,2356;3396,2281;3467,2281;3467,2310;3392,2356;3392,2281;3396,2281;3398,2356;3392,2281;3317,2281;"
+                             "3317,2206;3392,2206;3392,2281;3392,2206;3467,2206;3467,2281;3396,2281;3317,2206;3242,2206;3242,2156;"+
                             "3275,2131;3317,2131;3317,2206;3317,2131;3392,2131;3392,2206;3392,2206;3392,2131;3467,2131;3467,2206;"
+                             "3542,2206;3467,2206;3467,2131;3542,2131;3542,2206;3542,2131;3617,2131;3617,2206;3624,2206;3617,2206;"+
                             "3617,2131;3620,2131;3392,2131;3392,2078;3467,2078;3467,2131;3542,2131;3467,2131;3467,2078;3542,2078;" +
                             "3542,2131;3542,2078;3617,2078;3617,2131";
        Scanner read = new Scanner(point).useDelimiter("[;,]");       
        Graphics2D g2 = (Graphics2D)g;
        g2.setColor(Color.BLACK);
        while (read.hasNextInt()) {
             int x = (int)read.nextInt()/10;
             int y = (int)read.nextInt()/10;
             p.addPoint(x,y);
        read.close();
        g2.drawPolygon(p1);       
    }Thanks in advance..
regards,
tenlee
Edited by: tenly on Aug 18, 2009 10:46 PM

Hi,
Just out of curiosity I gave it a shot. It seems that only on the upper left side the result is a bit different than the result that you expect (according to the picture with the red dots).
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class OuterShape extends JPanel {
    public static void main(String[] args) {
     SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
          new OuterShape().createGUI();
    private final Shape outerShape;
    private final Polygon polygon;
     outerShape = createOuterShape();
     polygon = createPolygon();
     this.setOpaque(true);
     this.setBackground(Color.GREEN);
    private static final long serialVersionUID = 1L;
    private static String point = "3331,2305;3317,2332;3317,2356;3310,2356;3302,2355;3331,2305;3317,2286;3317,2281;3392,2281;3392,2356;3317,2356;"
         + "3317,2332;3331,2305;3303,2278;3312,2281;3317,2281;3317,2286;3303,2278;3254,2313;3249,2309;3249,2281;"
         + "3295,2281;3303,2278;3295,2281;3249,2281;3242,2241;3242,2206;3317,2206;3317,2281;3312,2281;3249,2309;"
         + "3233,2159;3344,2079;3317,2102;3317,2131;3275,2131;3242,2156;3242,2206;3242,2241;3249,2281;3344,2079;"
         + "3349,2078;3352,2074;3361,2093;3385,2078;3392,2078;3392,2131;3317,2131;3317,2102;3344,2079;3352,2074;"
         + "3349,2078;3361,2093;3390,2070;3650,2070;3656,2078;3617,2078;3542,2078;3467,2078;3392,2078;3385,2078;"
         + "3650,2070;3731,2143;3722,2141;3714,2131;3620,2131;3617,2131;3617,2078;3656,2078;3731,2143;3565,2249;"
         + "3617,2211;3617,2206;3624,2206;3620,2131;3714,2131;3722,2141;3565,2249;3494,2296;3513,2281;3467,2281;"
         + "3467,2206;3542,2206;3542,2261;3565,2249;3542,2261;3542,2206;3617,2206;3617,2211;3494,2296;3465,2315;"
         + "3467,2310;3467,2281;3513,2281;3465,2315;3390,2365;3313,2365;3302,2355;3310,2356;3317,2356;3392,2356;"
         + "3398,2356;3396,2281;3467,2281;3467,2310;3392,2356;3392,2281;3396,2281;3398,2356;3392,2281;3317,2281;"
         + "3317,2206;3392,2206;3392,2281;3392,2206;3467,2206;3467,2281;3396,2281;3317,2206;3242,2206;3242,2156;"
         + "3275,2131;3317,2131;3317,2206;3317,2131;3392,2131;3392,2206;3392,2206;3392,2131;3467,2131;3467,2206;"
         + "3542,2206;3467,2206;3467,2131;3542,2131;3542,2206;3542,2131;3617,2131;3617,2206;3624,2206;3617,2206;"
         + "3617,2131;3620,2131;3392,2131;3392,2078;3467,2078;3467,2131;3542,2131;3467,2131;3467,2078;3542,2078;"
         + "3542,2131;3542,2078;3617,2078;3617,2131";
    public void createGUI() {
     JFrame frame = new JFrame();
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     frame.add(this);
     frame.setSize(600, 600);
     frame.setLocationRelativeTo(null);
     frame.setVisible(true);
    private Shape createOuterShape() {
     Scanner read = new Scanner(point).useDelimiter("[;,]");
     Path2D pathOne = new Path2D.Double(Path2D.WIND_NON_ZERO), pathTwo = new Path2D.Double(
          Path2D.WIND_EVEN_ODD);
     boolean opened = false;
     while (read.hasNextInt()) {
         int x = (int) read.nextInt();
         int y = (int) read.nextInt();
         if (opened) {
          pathOne.lineTo(x, y);
          pathTwo.lineTo(x, y);
         } else {
          pathOne.moveTo(x, y);
          pathTwo.moveTo(x, y);
          opened = true;
     pathOne.closePath();
     pathTwo.closePath();
     read.close();
     Area area = new Area(pathOne);
     area.add(new Area(pathTwo));
     if (!area.isSingular()) {
         Area newArea = new Area();
         Path2D singlePath = new Path2D.Double();
         PathIterator pi = area.getPathIterator(null);
         double[] coords = new double[6];
         while (!pi.isDone()) {
          int type = pi.currentSegment(coords);
          switch (type) {
          case PathIterator.SEG_MOVETO:
              newArea.add(new Area(singlePath));
              newArea = new Area();
              singlePath.moveTo(coords[0], coords[1]);
              break;
          case PathIterator.SEG_CLOSE:
              singlePath.closePath();
              break;
          case PathIterator.SEG_CUBICTO:
              singlePath.curveTo(coords[0], coords[1], coords[2],
                   coords[3], coords[4], coords[5]);
              break;
          case PathIterator.SEG_LINETO:
              singlePath.lineTo(coords[0], coords[1]);
              break;
          case PathIterator.SEG_QUADTO:
              singlePath.quadTo(coords[0], coords[1], coords[2],
                   coords[3]);
              break;
          newArea.add(new Area(singlePath));
          pi.next();
         area = newArea;
     return area;
    private Polygon createPolygon() {
     Polygon polygon = new Polygon();
     Scanner read = new Scanner(point).useDelimiter("[;,]");
     while (read.hasNextInt()) {
         int x = (int) read.nextInt();
         int y = (int) read.nextInt();
         polygon.addPoint(x, y);
     read.close();
     return polygon;
    @Override
    protected void paintComponent(Graphics g) {
     super.paintComponent(g);
     Graphics2D g2 = (Graphics2D) g.create();
     g2.translate(-3200, -2000);
     g2.setColor(Color.WHITE);
     g2.fill(outerShape);
     g2.setColor(Color.BLACK);
     g2.draw(polygon);
}Piet

Similar Messages

  • How to get rid of the black border around the artboard

    Hopefully my last question for tonight.
    I need to get rid of the black border around the artboard. The two images show my drawing lined up with the art board and then inside the artboard. The dark gray is not the artboard.
    As you see, the artboard has a black border. I need to get rid of it. It shows up in my project when my color key is green. The black won't go to transparent.
    So how-to get rid of the border? Thanks
    ***Update***
    I figured it out. View > Hide Artboards. Maybe this will help someone. Doesn't change the fact my spider looks like a tick:)

    Doesn't change the fact my spider looks like a tick:)
    Try to get hold of a real spider and take a look at its anatomy, specially where the legs sprout from :-)

  • Text types along the horizontal border of the text box instead of being written inside of it. What's wrong?

    I created a text box by dragging the horizontal text tool.
    But when I start typing, the text aligns along the upper border of the box instead of being written inside of it.
    It looks like this.
    How can I fix this, so that the text is inserted inside the defined box?
    Much thanks in advance!

    I just figured it out! Can't believe I was this clueless.
    I just had to change the font height back to 100%. Haha

  • How to display the out put of the sql query in a text file using forms

    I want to display the out put of the sql query in a text file using forms 6.0.Same could be done using spool command in sqlplus but i want it using forms....Fiaz

    Have a look at the text_io package:
    http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/oraini/c_text_io.html&vtTopicId=
    cheers

  • Importing the out-put to the exel

    Hi all,
    iam very new to the unix and sql,
    just i want to know how to export the out-put of the query into exel using unix(spool)

    A lot of people rob banks too.
    You can spool an output to a file delimiting columns with commas if you wish. But that is outputting a file not outputting to Excel.
    Personally I'd fire anyone in a data center I caught outputting Oracle into a non-secure unauditable form and putting the organization at risk.

  • The outer layer of the power line was broken

    The outer layer of the power line was broken and it does not work now

    A broken power adapter is not safe to use. Discard it and buy a new one from Apple.
    http://store.apple.com/us/mac/mac-accessories/power

  • Why does my table heading butt up against the top border of the table?

    I've created a one-cell table that is acting as a section heading in a quick reference guide.
    The problem is that the heading text butts up agains the top border of the table, as shown below.
    I've tried changing the cell margins in the table designer, and changing the spacing options in the paragraph designer.
    Or is there a better way than a table to accomplish this heading?
    How do I fix this?
    Cindy

    Cindy,
    Check the Paragraph designer to see what cell location (Top, middle or bottom) is specified for the paratag used for the heading in the table. Also, check to see if there are any positional overrides for the margins specified in the paratag. These will trump whatever settings you specify via the Table designer.

  • How do I add the white border on the photo?

    Hi, I am a new beginner. How do I add the white border on the photo?

    This forum is actually about the Cloud, not about using individual programs
    Once your program downloads and installs with no errors, you need the program forum
    If you start at the Forums Index http://forums.adobe.com/index.jspa
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says ALL FORUMS) to open the drop down list and scroll

  • Have just found a hickup on the Lion software 10.7.2 When using a access point that you name with letters that is only in Norwegian æøå you will loose connections and only get time out. So the solution will be to rename the access point.

    Any solution beside to rename the wifi access point without the spesial Norwegian letters æøå?

    Your points match mine pretty well,though here are some thoughts:
    1. I thought about this theory myself this morning (iTunes possibly causing more issues), but I haven't been able to verify it.
    2. When I set up a new user it seemed better for a while, but the issue croppped back up. Yesterday I fully wiped the machine and reinstalled from scratch. I did not reimport my user from TimeMachine, but the problem has come back. My thinking was that I might have some really old software or prefs hanging around causing the issue. No dice.
    3. This is my current theory of the issue, so my next step will be to pull the RAM from Crucial and see how the system behves. IF that doesn't eliminate the problem, I'll pull the factory installed RAM and replace it with the 3rd party RAM. The odd thing is how many people seem to have similar issues - I know two personally, and have seen several posts on forums. I think the most common point for this happening was the 10.7.2 update, which would point to software as the culprit.
    4. That matches my experience.
    My hope is that this will be repaired in the forthcoming 10.7.3 release (current production version is 10.7.2), but otuside of what I noted above, I'm at a loss.

  • How do I get dust out from under the scre

    I have a Zen Sleek and there is vey noticable dust under the screen. It's very annoying. It may have gotten in through the edges of the screen. I've searched the forums, and people are talking about this "canned air." Where can I get it'sMessage Edited by Ryche on 03-2-200602:53 PM

    I had the same problem. Used can of compressed Air, and it did nothing more than scatter the dust all over the screen as opposed to the corner it was in. I even was able to peal back the screen front a little to get the straw from the canned air under the screen. Still did nothing. This is the 2nd played Ive had with this issue, the st player was exchanged due to this issue. I would also like to point out that I called creative tech support and they supposedly have no knowledge of this issue, although on every single review site you look the sleek up on, that is the most common complaint. I'll also add that I sell these devices where I work and Ive heard some customer feedback, and they too have the same complaint. Any ways Ive searched far and wide and it seems the only other solution I have is to rip off the screen shield and clean the LCD directly. Now if I was to do that I'm then presented with the issue of getting it back on without glue damaging the LCD. I know this is a long rant but if there is any one who actually read this whole thing and has some advice, please let me know. Thank you very Much

  • The whole headphone jack is stuck in my iPhone 4 it just snapped off when I puller it out how do i get it out seem as the whole jack is stuck in there

    The whole of my headphone jack snapped off and when I mean the whole thing I literally mean the whole jack how do I get it out as I don't really want to pay hinder of pounds to get it fixed , thanks a lot

    There's quite a few clever suggestions for how to do this. See "More Like This" over there >>>>>

  • How to get rid of border in the RowSetBrowser

    I use the RowSetBrowser object with rounded corners option switched off like this:
    RowSetBrowser.setUseRoundedCorners(false);
    This creates the web page where the records are shown within the table with ugly border.
    How to get rid of this table border ?
    I have not found any relevant method in the class oracle.jbo.html.databeans.RowSetBrowser.
    This is what is generated by JSP:
    <TABLE WIDTH="100%" BORDER="1" CLASS="clsTableControl" >
    </TABLE>
    This is what I want:
    <TABLE WIDTH="100%" BORDER="0" CLASS="clsTableControl" >
    </TABLE>
    I have to use Netscape as the browser and therefore can not override BORDER setting in the CSS class definition.
    This works fine for IE but not for Netscape:
    .clsTableControl
    border-style:none;
    borderstyle:none;
    Anybody experienced similar problem?
    Thanks,
    Michael
    null

    I've found the solution, this way it worked:
    "Concepts: " & CStr({DevelopmentTracking_SELECT.Concepts}, 0)

  • To get the the out put of the procedure..help needed

    hi all,
    i have a procedure :
    CREATE OR REPLACE PROCEDURE EN_GetCategory
         StaffID IN      VARCHAR2 DEFAULT NULL,
         ResultCategory OUT      VARCHAR2
    AS
    v_exec_tx varchar2(2000);
         Condition VARCHAR2(1000);
         Category VARCHAR2(1);
         SQL_ADV VARCHAR2(2000);
         Cnt          NUMBER(10);
         Cnt1          NUMBER(10);
    CURSOR curCategory IS
    SELECT SMC.Category,SMC.Condition FROM ST_MS_Category SMC ORDER BY OrderRowNo;
         BEGIN
              EXECUTE IMMEDIATE 'TRUNCATE TABLE TMP';
              OPEN curCategory;
              FETCH curCategory INTO Category, Condition;
              while curCategory%FOUND
              LOOP
              BEGIN
                   v_exec_tx:='SELECT COUNT(*) FROM ST_EMPLOYEE WHERE StaffID=''' || EN_GETCATEGORY.STAFFID ||''' AND ' || EN_GETCATEGORY.CONDITION;
                   EXECUTE IMMEDIATE v_exec_tx into Cnt;
    IF Cnt > 0 THEN                              SELECT COUNT(*) INTO CNT1 FROM tmp ;
              IF CNT1> 0     THEN
                                       UPDATE tmp SET CAT = Category ;
              ELSE
                                       INSERT INTO tmp VALUES (Category );
              END IF;
              END IF;
              FETCH curCategory INTO Category, Condition;
                   END;
              END LOOP;
              CLOSE curCategory;
              BEGIN
                   FOR REC IN ( SELECT CAT FROM tmp
                   LOOP
                   EN_GetCategory.ResultCategory := REC.CAT;
                   END LOOP;
              END;
         END;
    i need to execute this procedure..
    i tried EXEC EN_GETCATEGORY('812005','');
    but getting error invalid sql statemnt..
    i think for this we have to write some more code can u please help to to find the output ofthis procedure..
    Thanks In advance

    Hi,
    i tried EXEC EN_GETCATEGORY('812005','');It's execute Procedure_name('Parameters');
    Regds.What tosh! "exec" is perfectly ok to use to call a procedure.
    The problem is with the OUT parameter. You need to declare a variable into which the OUT value can be put.

  • When I export to a PNG in Illustrator I get a small reflection of the image content at the lower border of the PNG...how do I get rid of this?

    Notice the one pixel blue lines on the bottom of the logo.

    CoreyKat,
    If you select the artwork and select one of the bottom Reference Points in the Transform palette, is the Y value an integer?
    If not, what happens if you move the artwork so that it is?

  • Getting duplication of records in the out put of the report on multipro..

    hai ,
          We are trying to execute a report on a multiprovder.While executing the report  we are getting duplication of records while in case if we are removing the created 'new selection' or 'new fromula' in the query designer we are not getting the duplicate records.
    Now as per our requirement we do not need duplicate records.
    Plz could any one help me out with this problem

    Hi Jvr,
    $server | ($_ -split '=')[1] -replace '}' is working.. :)
    The email doesn't have @{ = }, its only displayed in the output.
    Any help on the REGEX part?

Maybe you are looking for