Hi I have a geometry problem.Can anyone help with java code

Hi I have a non simple polygon . My job is to make it a simple. for that First I need to find the intersecting lines say line AB intersects line CD. If so then I must replace AB & CD with AC & BD or AD or BC which ever keeps the polygon closed . So can anyone help me out with this code
import java.io.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
public class Simple{
static int POINTWID = 4; // size of points
// the x and y arrays hold the coordinates
// the B array is the order of the points in the polygon
// You want to fill the C array with the simple polygon
static double x[] = new double[200];
static double y[] = new double[200];
static int B[] = new int[200]; // the permutation matrix
static int C[] = new int[200]; // the one that becomes simple
static SimpleFrame myFrame;
static int numPoints = 3;
public static void main(String args[]) {
makePolygons();
// Create the frame to draw on
myFrame = new SimpleFrame();
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(600, 600);
myFrame.setVisible(true);
public static void makePolygons(){
// Build an array of random points in the unit square
for(int i = 0; i < numPoints; i++){
x[i] = Math.random();
y[i] = Math.random();// Sample program
B[i] = i; // default permutation
// Create the simple polygon
createSimplePolygon();
* This is the only function you need to mess with
public static void createSimplePolygon(){
// Initialize the C[] array with the identity permutation
for(int i = 0; i < numPoints; i++)
C[i] = i;
// Bubble sort the points from left to right
for(int i = 0; i < numPoints; i++)
for(int j = 0; j < numPoints - 1; j++)
if(x[C[j]] > x[C[j+1]]){
int temp = C[j];
C[j] = C[j+1];
C[j+1] = temp;
public static class SimpleFrame extends JFrame{
public static JSlider numPointsSlider;
public SimpleFrame()
super("Create you own Simple Polygon");
Container content = getContentPane();
content.setLayout(new java.awt.BorderLayout());
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setPreferredSize (new java.awt.Dimension(300, 400));
tabbedPane.addTab("Scrambled", new ScrambledPanel());
tabbedPane.addTab("Simple", new SimplePanel());
content.add(tabbedPane, java.awt.BorderLayout.CENTER);
// Slider for the number of points
numPointsSlider = new JSlider (javax.swing.SwingConstants.HORIZONTAL,
3, 100, 11);
numPointsSlider.addChangeListener (new javax.swing.event.ChangeListener () {
public void stateChanged (javax.swing.event.ChangeEvent evt) {
numPointsSliderStateChanged (evt);
content.add(numPointsSlider, java.awt.BorderLayout.SOUTH);
private void numPointsSliderStateChanged (javax.swing.event.ChangeEvent evt) {
numPoints = numPointsSlider.getValue();
makePolygons();
repaint();
public static class ScrambledPanel extends JPanel{           
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
// First set the scaling to fit the window
Dimension size = getSize();
int Xwid = (int) (0.95 * size.width);
int Ywid = (int) (0.95 * size.height);
// First draw the segments
g2.setColor(Color.red);
for(int i = 0; i < numPoints; i++)
g2.drawLine((int) (Xwid * x[B[i]]),
(int) (Ywid * y[B[i]]),
(int) (Xwid * x[B[(i+1) % numPoints]]),
(int)(Ywid * y[B[(i+1) % numPoints]]));
// Now draw the points
for(int i = 0; i < numPoints; i++){
g2.fillRect((int) (Xwid * x) - POINTWID,
(int) (Ywid * y[i]) - POINTWID,
2*POINTWID + 1, 2*POINTWID + 1);
public static class SimplePanel extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
// First set the scaling to fit the window
Dimension size = getSize();
int Xwid = (int) (0.95 * size.width);
int Ywid = (int) (0.95 * size.height);
// First draw the segments
g2.setColor(Color.red);
for(int i = 0; i < numPoints; i++)
g2.drawLine((int) (Xwid * x[C[i]]),
(int) (Ywid * y[C[i]]),
(int) (Xwid * x[C[(i+1) % numPoints]]),
(int)(Ywid * y[C[(i+1) % numPoints]]));
// Now draw the points
for(int i = 0; i < numPoints; i++){
g2.fillRect((int) (Xwid * x[i]) - POINTWID,
(int) (Ywid * y[i]) - POINTWID,
2*POINTWID + 1, 2*POINTWID + 1);

Hi I am sorry I could explain you properly . Ok
My program gives me a polygon(as you can see when u
run this program)But the polygon is a non simple
polygon.So to make this polygon we must remove all
the crossings betweeen edges in the polygon.The
algorithm which i gave will remove all the crossings
and make the polygon simple.You did not give an algorithm!
SO my job is to take the
existing code and implement the algorithm for this
program in the Createsimpelpolygon() function. For
this First the program must find whether two edges
cross if they cross then swap the vertices like
replace AB & CD with AC & BD or AD & BC.Which ever
keeps the polygon closed . Still not entirely clear to me. You cannot just go and replace vertexes from a polygon: that way you'll end up with a different polygon.
So as we go on we find the
many crossings and iterate the algorithm on all the
crossings until we get simple polygon.Like I said: I don't really understand what it is you're after. You did not respond to my suggestions, so I gather it is not what you're after?
What about Polygon Tessellation (Google for it)? Perhaps that's what you want.
Also, why do you not create a (or use java.awt's) Point class and a Polygon class which holds a java.util.Set of Point's? Your current code looks rather messy.

Similar Messages

  • Can anyone help with this code

    i am trying to create a html5 video gallery for my website  I was wondering if anyone can help me with this code :  Am i missing something got this from the adobe widget browser i can get the button fuctions but i can not seem to get the video to play or work.. 

    This is the full page i am still working on it but the video code which i posted earlier is not working...    
    123456789101112131415
    Home
    Biography
    To Be Lead
    Gallery
    Videos
    Memorial Page
    Wallpaper
    Blog
    Forum
    Contact
    Randy Savage Bio
    Randy's Facts 101
    His Early Career
    Randy's Career in the WWF
    Randy's Career in WCW
    The Mega Powers  
    Mega powers Bio Mega Powers Facts 101 
    PM to fans and Elizabeth
    Randy's Radio interview
    His Death
    Elizabeth Hulette 
    Elizabeth Bio Elizabeth Facts 101 Her Career in the WWF Her Career in WCW Later Life Farewell to a Princess Elizabeth's Radio Interview Elizabeth Death 
    Sherri Martel
    Gorgeous George
    Team Madness
    Early Years
    ICW Gallery
    WWF Gallery
    WCW Gallery
    NWO Gallery
    Memorial Page for Randy
    Memorial Page for Elizabeth
                          Video of the Month    
    Site Disclaimer
    Macho-madness is in no way in contact with World Wrestling Entertainment. All photos are copyright to World Wrestling Entertainment or their respective owners and is being used under the fair copyright of Law 107.
    ©macho-madness.net All right's Reserved.  
            Affiliates
    Want to be an affiliate, elite, or partner site? Email: [email protected] with the list of things below.
    Place in the subject of email: “Randy Savage Online Affiliation”.
    Name: 
    Email: 
    Site Name: 
    Site URL: 
    When Will The Site Be Added?:
                        To see A List Click Here...
    ©macho-madness.net All right's Reserved.  
    Offical Links

  • My ipad 3 is 7 month old and I have the following problems can anyone help please?

    1) it doesn't always fully charge
    2) sometimes closes page/app I am on without me touching middle button
    3) sometimes goes dim then I have to lock and unlock screen to fix
    4) freezes and fuzzy on FaceTime

    Do a reset (Hold Sleep/Wake and Home buttons about 10 secs or more till Apple logo appears, ignore the Slide to Power Off that appears)
    Note: You will not lose any data.

  • Can anyone help with my code?

    Hello, I bought Photoshop last december, I got my invoice and everything went well untill the 30 days trial end, I can't use it anymore is asking for a code and I can't find it ANYWHERE, please help.

    You would need to deal directly with Adobe users here do not have access to Adobe Users databases.

  • Can anyone help with error code 21

    I have an iPhone 4s, when I went to update the software I got stuck on the iTune screen, and giving me error code 21.
    I downloaded the lastest iTune, my computer softwares are up to date.
    Everytime I try to restore my phone, will come back with code 21
    Thanks...

    From this support document http://support.apple.com/kb/TS3694 error 21.
    Error 20, 21, 23, 26, 28, 29, 34, 36, 37, and 40
    These errors typically occur when security software interferes with the restore and update process. Use the steps to troubleshoot security software issues to resolve this issue. In rare cases, these errors may be a hardware issue. If the errors persist on another computer, the device may need service.

  • Can anyone help with iPlayer and Sky Mobile?

    Ok, I'm so close to giving up with this useless phone. There are 3 apps on my N97 which give me a constant headache.
    BBC iPlayer
    Sky Mobile*
    YouTube
    *I should point out that I only use Sky Mobile to set recordings on my Sky+. I do not use it for, nor have any desire to use it for actually watching Mobile TV.
    All of these apps work absolutely fine over my home WiFi network. It's when I try to use them over 3G (my Vodafone Live! connection) that I start running in to trouble.
    All 3 give me connection problems, errors, and simply refuse to load half the time when on 3G. I got so annoyed I just did a hard reset the other week, and magically all three started working again. However, now 2 of them are failing me again. YouTube (touch wood) is working fine at the moment, but iPlayer and Sky Mobile just aren't.
    iPlayer sometimes works. But sometimes I get script errors (unable to load content), and sometimes it says something about checking my connection settings. I wouldn't mind but it's not actually possible to access any options for the iPlayer. Even in application settings there are no options you're able to set.
    Sky Mobile simply flat out refuses to work ever on 3G. But it did after I did a hard reset for a couple of weeks, now it just stopped working! It wont even load. It just gives the error message 'Unable to connect to network - please check connection settings" or something along those lines.
    I've tried so many different things. Tried setting my internet connections to 'always ask', tried setting it to default to Vodafone Live! all the time, tried setting my video streaming settings to WAP, all sorts. Every combination I can think of.
    I just can't wait to get rid of this phone. I've put so many people off buying one. They see it and think it's all swish and cool, and I just say 'Don't. You'll regret it'. I can't wait for my contract to be up so I can upgrade to an iPhone now Vodafone have got them.
    Can anyone help with these problems? Thanks in advance, but I don't hold out much hope...

    About iPlayer.
    Have a chat with Vodaphone. Streaming iPlayer over 3G IS allowed on Vodaphone contract, unlike my O2 contract. As long as your contract allows it, and you have the correct AP address, it should be fine. Vodaphone should be able to give you the setting.
    Mine only works over Wlan.
    FWIW, "... streaming over 3G is not currently available on iPhone handsets on any mobile network".
    p.s. Just to be clear. You say  "Tried setting my internet connections to 'always ask', tried setting it to default to Vodafone Live!".
    iPlayer uses the Nokia browser "Web". So that's where you should make the setting "Ask when needed". It should then offer you the choice of whatever you've set in Destinations> Internet> then select whatever you've chosen as your GPRS connection.(as advised, or sent to you by Vodaphone).

  • Can anyone help with Double Command issues. This a specific keyboard question and they do not seem to know.

    Before I go into a lengthy explanation of the problem: Can anyone help with Double Command issues. This a specific keyboard question and they do not seem to know.
    Thanks much.
    Emile

    Choose Force Quit from the Apple menu and close Mail from there.
    (103661)

  • Can anyone help with issue whereby Music, Podcasts and Audiable Book Apps keep stopping when listing via Headphones following IOS 7.01 Updates on Iphone 4?

    Can anyone help with issue whereby Music, Podcasts and Audiable Book Apps keep stopping when listing via Headphones following IOS 7.06 Updates on Iphone 4?
    I have tried the following all ready:
    Resetting Phone
    Resetting Settings on phone
    Change Headsets to speakers
    Reinstalled Phone
    Updated to IOS 7.1
    No of the above has resolved the issue does anyone have any ideas?

    Can anyone help with issue whereby Music, Podcasts and Audiable Book Apps keep stopping when listing via Headphones following IOS 7.06 Updates on Iphone 4?
    I have tried the following all ready:
    Resetting Phone
    Resetting Settings on phone
    Change Headsets to speakers
    Reinstalled Phone
    Updated to IOS 7.1
    No of the above has resolved the issue does anyone have any ideas?

  • Gmail on iphone was working fine until yesterday when it prompted me with the message cannot get mail user name or password for gmail is incorrect, i have tried deleting the account and re-created a new account, same problem, can anyone help?

    gmail on iphone was working fine until yesterday when it prompted me with the message "cannot get mail user name or password for gmail is incorrect", i have tried deleting the account and re-created a new account, same problem, can anyone help?

    paulcb, you're a genius, it worked, thank you so much, you don't know how much stress you have taken off my shoulders, I am constantly on my email in my iphone everyday.  Thanks a million, take care. Robert.

  • Please can anyone help with the continuing password rejection problem with email.Ipad and other systems work fine but despite reloading my password on imac it bounces back.Apple store has been visited and I have tried everything they suggest.

    Please can anyone help with the continuing password rejection problem with email on my imac.My Ipad and other systems work fine but despite reloading my password on imac it bounces back.Apple store has been visited and I have tried everything they suggest.

    I use free Yahoo mail webMail access because folders I created in webmail access doesn't get set up in Apple Mail. While I was searching for post about password and keychain issues, I stumbled on several threads that complain about Mail folder issues, so I'm holding off on Apple Mail.
    On the password and keychain issue that your post is all about.  I've been using login keychain to save and automatical fill my login screens for a year or so successfully, with Safari and Chrome. Automatic form fill also works for Facebook login. Unfortunately, about 4 to 6 months ago, automatic password form fill stopped working with Yahoo webmail, while still worked for GMail (Safari and Chrome). I tried deleting the password entry for my two Yahoo email accounts to start fresh, but neither Safari not Chrome will even ask me if I want to save the password. I was so frustrated that I eventually installed the keypassX 0.43 (password manager) that is quite primitive sompare to OS X's keychain (when it works). Probably no surprise to you yet.
    The surprise, to me at least, is that, for whatever reason, password auto form-fill from keychain started working again for Yahoo webmail login on Safari about 5-7 days ago. Still doesn't work on Chrome!
    Two tips I can share, at least with webmail access:
    1. Password is save only for one of my yahoo mail accounts. When I login in with my other yahoo account, I get no prompt to save the password, and form fill doesn't work when I try to log in a second time with my other Yahoo mail account.
    2. On inspection of my login keychain, I see a webform password item saved for my Yahoo account that works with keychain. The name of the password is: login.yahoo.com(MyAccountName1#). When I open the password item and look in the Access Control tab, I see Safari and Chome are listed as allowed to access this password item..
         I also an "Internet password" item with a name of just login.yahoo.com. When I open the the password item, it looks just like the password item created for MyAccountName#1, but the MyAccountName#2 is listed in the Account field. Inside the Access Control tab, no apps are listed in access permission. I added Safari and Chrome to the lists of allowed app, saved the password item.
    Now when I bring up the Yahoo login page(by bookmark) on Safari, form fill fills in MyAccountname#1 for name and the proper password and I can login in. When I change the name to MyAccountName#2, the correct password is retrieved and I can log in! Alas, it still doesn't work on Chrome.
    BTW, I changed the password item type from "Internet password" to "Web Form password" and saw no difference! I also edited the name to be "login.yahoo.com (MyAccountName#2)" to look like the web form password item that works, but it has no effect either.
    From my experimentation, here's my observation:
    1. A Web Form password item is created for the first account name(MyAccountName#1) for login.yahoo.com and typed as Web Form password. When I log in using MyAccountName#2, an Internet Password is created, but no applications are listed as allowed to access the password item, even when the password item was created after just logged in and logged out to yahoo with the account name and password for MyAccountName#2.
    2. Manually adding Safari as an app that is allowed to use the password item works. Doesn't work with Chrome!
    The version of Safari I'm using is Version 5.1.7 (6534.57.2). My installed version of Chrome is Version 21.0.1180.79 beta.

  • Can anyone help with problem updating iphone5s cant get anything only apple on screen sometimes screen flashes blue

    can anyone help with problem updating iphone5s cant get anything only apple on screen sometimes screen flashes blue

    Hey damien555,
    Thanks for the question, I understand how frustrating this may be. It sounds like the update process may have been interrupted, and to resolve the issue, we’ll need to restore your device in recovery mode with iTunes:
    If you can't update or restore your iOS device
    http://support.apple.com/kb/HT1808
    Thanks,
    Matt M.

  • Hi, can anyone help with the problem I am having with pro book 4440s? I can't boot into windows 7.

    Hi, can anyone help with the problem I am having with pro book 4440s?  I can't boot into windows 7, nor can I enter the bios cause i fogot the password. the error I am getting says "windows failed to start. a recenr hardware or software change might be the cause.   it then gives me options to boot from a disc but I can't do that cause I am unable to get into the bios to change it to boot from a disc.
    The error message goes on :
    File: \Boot\BCD
    Status: oxcoooooof
    info: An error occurred while attempting to read the boot configuration.
    the only two options on the screen are enter=continue and ECS=exit
    I just can't get pass this screen.
    Please help.
    Thanks

    Hi,
    If you don't already have one, use another PC to create a Windows 7 Rescue CD.  Download the relevant ISO from the links below.
    Windows 7 32bit
    Windows 7 64bit
    You should use an application such as ImgBurn to burn the ISO to a CD - a guide on using ImgBurn to write an ISO to a disc is Here.  Once created, or if you already have this, tap away at the esc key as you start the notebook to enter the Start-up Menu.  Insert the Rescue CD.  Select Boot options ( usually f9 ), use the arrow keys to select the CD/DVD drive and hit enter.  You may also get a prompt to 'Press any key to continue' - do this if asked.
    When loaded, select Repair Your Computer and choose the Command Prompt.  When this loads, enter the following commands and hit enter after each one - include spaces as shown.
    Bootrec.exe
    bcdedit /export C:\BCD_Backup
    c:
    cd boot
    attrib bcd -s -h -r
    ren c:\boot\bcd bcd.old
    bootrec /RebuildBcd
    bootrec /fixmbr
    bootrec /fixboot
    Remove the Rescue CD and try rebooting the notebook.
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

  • How do I change DNS to Business Catalyst servers.  I am having problems can anyone help please?

    How do I change DNS to Business Catalyst servers.  I am having problems can anyone help please?

    What problem are you having?
    Have you read this KB? - Domain name and DNS: Quick reference

  • TS3999 I am unable to sync my Outlook calendar with my Iphone. I have noted that the Icloud Outlook add in is not ticked When I attempt to load it from the designated file nothing happens Can anyone help with this? Robyn

    I am unable to sync my Outlook calendar with my Iphone. I have noted that the Icloud Outlook add in is not ticked When I attempt to load it from the designated file nothing happens Can anyone help with this? Robyn

    Re: check that the appointments in my phone are going into iCloud calendars....exactly how do I do this?  I fear this is a really stupid question!
    My iCloud account is set up with my Apple ID as one email account (for example [email protected]) which is the email account I use to sign up for internet sites like Amazon, Apple,etc, so that I can differentiate vendors/mass emails.  But my default calendar on my iPhone is in a different email name (ie [email protected]) which I use for most communications to friends, relatives, etc. and it is this account that holds most of my appointments.  To further complicate things I have other email accounts that I use for business/professional and community work.  If I want all my calendars to show on my iPhone AND sync to my iCloud, do I set this at the phone level or the iCloud level?  or both?   
    Let me clarify....It looks like if I go into appointments that I previously set up through my personal account (ie above [email protected]) and edit the entry on my iPhone, selecting the iCloud "home" calendar within the entry, it will then sync to my iCloud account, no problem....do I have to do this to EVERY entry I have? or is there  a way to name my personal account as one to sync to iCloud?

  • HT1386 As soon as I plug my iphone4 (running 4.3.3) into my pc, it appears in the left hand column and the little wheel starts turning. Then it stops after a few seconds and itunes freezes. I have tried everything. Can anyone help. Thanks

    As soon as I plug my iphone4 (running 4.3.3) into my pc, it appears in the left hand column and the little wheel starts turning. Then it stops after a few seconds and itunes freezes. I have tried everything. Can anyone help. Thanks

    Hi Patrick,
    Yes, a very frusterating issue indeed. Someone else had mentioned a possible issue with real player, I tried getting rid of that and same issues. I even got completely rid of firefox for the moment. Guess what, problem still is persisting. I think this means it maybe something else altogether. I will go back to re-add firefox after I get this straightened out but now using Chrome for the moment.
    What I've also found out is that the sound can be restarted when I unplug and replug in the 3.5mm speaker cable from the audio output jack on the back of the computer. Any ideas?
    Thanks!

Maybe you are looking for