Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda