Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!