Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. Intersection between polygons

Hi community, I need a program to indicate if two polygons intersect in two points, will it be possible to do it through these codes that facilitate me? Thanks!!

2. Re: Intersection between polygons

I need a program
Sorry, we don't write code here. If you have some specific java programming questions about your code,

3. Re: Intersection between polygons

```
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package calculointereseccion;

/**
*
*/
public class CalculoIntereseccion {

* */**
* * * @param args the command line arguments
* * */
* *public static void main(String[] args) {
* * * *
* * * *
* * * *double n1 = 123;
* * * *double n2 = 356;
* * * *
* * * *Punto p1 = new Punto(n1 , n2);
* * * *
* * * *Punto p2 = new Punto();
* * * *p2.setCoordX(123);
* * * *p2.setCoordY(356);
* * * *
* * * *Punto listaPuntos1[] = new Punto [2];
* * * *listaPuntos1 [0] = p1;
* * * *listaPuntos1 [1] = p2;
* * * * * * * *
* * * *Poligono poligono1 = new Poligono("Mi primer poligono", "VERDE", listaPuntos1);
* * * *poligono1.imprimirPoligono (); * * * *
* * * *
* * * *
* * * *
* * * *
* *}
* *
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

package calculointereseccion;

public class Poligono {
* *
* *private String nombre;
* *private String color;
* *private Punto listaPuntos [];
* *
* *public Poligono (String nombreIn , String colorIn ,Punto listaPuntosIn []){
* * * *nombre = nombreIn;
* * * *color = colorIn;
* * * *listaPuntos = listaPuntosIn;
* *}
* *
* *public boolean interseccionPoligonos (Poligono otroPoligono){
* * * *boolean intersectan = false;
* * * *
* * * *Punto listaTmpOtroPol [] = otroPoligono.getListaPuntos();
* * * *
* * * *
* * * *for (int x=0; x < listaPuntos.length ; x++){
* * * * * *Punto p1 = listaPuntos [x]; * *
* * * * * *Punto p2 = null;
* * * * * *if (x != listaPuntos.length-1){
* * * * * * * * p2 = listaPuntos [x+1];
* * * * * *}else {
* * * * * * * * p2 = listaPuntos [0];
* * * * * *}
* * * * * *Linea lineaTmpPoligono1 = new Linea(p1, p2);
* * * * * *
* * * * * *
* * * * * *for (int j=0; j < listaTmpOtroPol.length ; j++){
* * * * * * * * * * * *
* * * * * * * *Punto p1otroPol = listaTmpOtroPol [x]; * *
* * * * * * * *Punto p2otroPol = null;
* * * * * * * *if (x != listaTmpOtroPol.length-1){
* * * * * * * * * * p1otroPol = listaTmpOtroPol [x+1];
* * * * * * * *}else {
* * * * * * * * * * p2otroPol = listaTmpOtroPol [0];
* * * * * * * *}
* * * * * * * *Linea lineaTmpOtroPoligono = new Linea(p1otroPol, p2otroPol);
* * * * * * * *boolean seIntersectanLasLineas = lineaTmpPoligono1.seInterectan(lineaTmpOtroPoligono);
* * * * * * * *if ( seIntersectanLasLineas == true){
* * * * * * * * * *intersectan = true;
* * * * * * * * * *break;
* * * * * * * *}
* * * * * * * *
* * * * * *}
* * * * * *
* * * * * *
* * * *}
* * * *
* * * *return intersectan;
* *}
* *
* *
* *public void imprimirPoligono () {
* * * *System.out.println("INICIO POLIGONO________");
* * * *for (int pos =0; pos < listaPuntos.length ; pos++){
* * * * * *Punto tmp = *listaPuntos [pos];
* * * * * *tmp.imprimirPunto();
* * * *}
* * * *System.out.println("___________FIN POLIGONO");
* *}
* *
* *public String getNombre() {
* * * *return nombre;
* *}

* *public void setNombre(String nombre) {
* * * *this.nombre = nombre;
* *}

* *public String getColor() {
* * * *return color;
* *}

* *public void setColor(String color) {
* * * *this.color = color;
* *}

* *public Punto[] getListaPuntos() {
* * * *return listaPuntos;
* *}

* *public void setListaPuntos(Punto[] listaPuntos) {
* * * *this.listaPuntos = listaPuntos;
* *}
* *
* *
* *
* *
* *
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package calculointereseccion;

/**
*
*/
public class Linea {
* *
* *private Punto pInicial;
* *private Punto pFinal;
* *
* *public Linea (Punto p1, Punto p2){
* * * *pInicial = p1;
* * * *pFinal = p2;
* *
* *}
* *
* *
* *public double pendiente (){
* * * *double pendiente = 0;
* * * *pendiente = pFinal.getCoordY() - pInicial.getCoordY() / pFinal.getCoordX() - pInicial.getCoordX();
* * * *return pendiente;
* *}
* *
* *public boolean seInterectan (Linea otraLinea){
* * * *boolean interseccion = false;
* * * *
* * * *
* * * *
* * * *return interseccion;
* *}
* *
* *public void imprimirLinea (){
* * * *System.out.println("INICIO LINEA___________");
* * * *System.out.print("PUNTO INICIAL: ");
* * * *pInicial.imprimirPunto();
* * * *System.out.print("PUNTO FINAL: ");
* * * *pFinal.imprimirPunto();
* * * *System.out.println("___________FIN LINEA");
* * * *
* *}
* *
* *public Punto getpInicial() {
* * * *return pInicial;
* *}

* *public void setpInicial(Punto pInicial) {
* * * *this.pInicial = pInicial;
* *}

* *public Punto getpFinal() {
* * * *return pFinal;
* *}

* *public void setpFinal(Punto pFinal) {
* * * *this.pFinal = pFinal;
* *}
* *
* *
* *
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package calculointereseccion;

public class Punto {
* *
* *private double coordX;
* *private double coordY;
* *
* *public Punto (){
* * * *coordX = 0;
* * * *coordY = 0;
* *}
* *
* *
* *//CONSTRUCTOR
* *public Punto (double coordXIn, double coordYIn){
* * * *coordX = coordXIn;
* * * *coordY = coordYIn;
* * * *
* *}
* *
* *
* *public void imprimirPunto (){
* * * *
* * * *System.out.println(" COORD X:" + coordX +" COORD Y:" + coordY );
* *
* *}

* *public double getCoordX() {
* * * *return coordX;
* *}

* *public void setCoordX(double coordX) {
* * * *this.coordX = coordX;
* *}

* *public double getCoordY() {
* * * *return coordY;
* *}

* *public void setCoordY(double coordY) {
* * * *this.coordY = coordY;
* *}
* *
* *
* *
* *
* *
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%*/```

4. Re: Intersection between polygons

Did you have any questions?

What happened to the code? It has lots of leading *s that make it useless for testing.