0

ANY recommendation for the title would be welcome. I have written this simple Slice class which just stores start position in degree and how many degrees it goes(CCW) until it ends. My problem is that I can't even think of an approach that would be able to help me write a function that takes 2 slices A and B and returns an array of slices. If B is contained entirely within A, we return a one-element array whose only element is B. But if B overlaps A, it returns a two-element array where item 0 is the part of B overlapped by A and item 1 is the rest of B (the part not overlapped by A). The nonoverlapping part of B can only follow A counterclockwise and cannot precede A.

static public Slice[] cutSlice(Slice A, Slice B){
    Slice[] slices = new Slice[2];
    //problem here
    return slices;
}
class Slice{
    public double degree;
    public double startPositionInDegree;
    Slice(double startPositionInDegree, double degree){
        this.startPositionInDegree = startPositionInDegree % 360;
        this.degree = degree;
    }

    @Override
    public String toString() {
        return "Starts at: " + startPositionInDegree + "\nAnd is " + degree + " long";
    }
}

In case you have trouble understanding I have attached an image that should help.

  • So the idea is if B is contained entirely within A, we return a one-element array whose only element is B. But if B overlaps A, we return a two-element array where item 0 is the part of B overlapped by A and item 1 is the rest of B (the part _not_ overlapped by A). Yes? – Kevin Anderson Dec 22 '20 at 13:59
  • [Look here](https://stackoverflow.com/questions/40584625/combine-two-segments-on-the-same-circle-if-they-overlap-or-intersect) for classification of sector intersections – MBo Dec 22 '20 at 14:48

0 Answers0