Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
Java - Divide Plan into sections

Given a point with x, y coordinates, I would like to understand in which sector are the points near it.

Check this image:

My Point is like this:

public class Node {

    public final int id;
    public final double coordinates[];
    public ArrayList<Node> candidateList;

    public Node(int id,double... values){
        this.id=id;
        this.coordinates=values;
    }

    public int distance(Node other){
        double result = 0;
        for (int x = 0; x<this.coordinates.length;x++){
            result+=(this.coordinates[x]-other.coordinates[x])*(this.coordinates[x]-other.coordinates[x]); //TODO time difference with pow

        }
        return (int) Math.round(Math.sqrt((result)));
    }
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You picture shows 8 sectors, and you can find sector number with three simple conditions (x and y are coordinates relative to center):

x < 0
y < 0
abs(x) < abs(y)

These three conditions give three bits of information to define 2^3=8 possible states (sector number). So you just have to make a table to match every combinations of condition results to the sector number. For example:

0 0 1 => your sector 1   //x positive, y positive, abs(y)>abs(x)
0 1 0 => your sector 3

If you want more sectors, it would simpler to use angle-based approach. For example, for 16 sectors:

//note reverse argument order due to your sector numbering
angle = atan2(x, y)  
if angle < 0 then 
  angle = angle + 2 * Pi
sector = 1  + Floor(angle * 8.0 / Pi)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda