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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Intersection between polygons

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!!
    Attached Files Attached Files

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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,
    post your code (wrapped in code tags) and ask your questions about it.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Intersection between polygons

     
    /*%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
     
    /*
     * To change this license header, choose License Headers in Project Properties.
     * 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 license header, choose License Headers in Project Properties.
     * 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 license header, choose License Headers in Project Properties.
     * 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. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Intersection and Union of Three or more Sets
    By robertm08 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 19th, 2013, 10:18 AM
  2. Intersection of two loops
    By sengreen in forum Loops & Control Statements
    Replies: 3
    Last Post: May 26th, 2013, 12:44 PM
  3. INTERSECTION OF TWO LIST
    By muhammad waqar in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 5th, 2013, 08:09 AM
  4. Not sure what kind of loop I need to use for an intersection program
    By sessypeanut in forum Loops & Control Statements
    Replies: 4
    Last Post: December 21st, 2012, 11:11 PM
  5. draw 4 different polygons.
    By liulca in forum What's Wrong With My Code?
    Replies: 36
    Last Post: December 12th, 2012, 12:11 PM

Tags for this Thread