How to get overlapping rectangle coordinates

后端 未结 5 1340

Assume I have the following overlapping rectangles (\"a\" and \"b\"):

aaaaaaaa
aaaaccccbbbbb
aaaaccccbbbbb
aaaaccccbbbbb
    bbbbbbbbb
    bbbbbbbbb
5条回答
  •  情歌与酒
    2021-02-09 05:04

    Assume:

    Points of   rectangle R1: R1.A(x,y), R1.B(x,y), R1.C(x,y), R1.D(x,y)   
    Points of   rectangle R2: R2.A(x,y), R2.B(x,y), R2.C(x,y), R2.D(x,y)   
    Overlapping rectangle RO: RO.A(x,y), RO.B(x,y), RO.C(x,y), RO.D(x,y)    
    Standard cartesian coordinates (positive is right and upwards).
    

    Overlapping rectangle RO computes as follows with C#:

    RO.A.x = Math.Min(R1.A.x, R2.A.x);
    RO.A.y = Math.Max(R1.A.y, R2.A.y);
    RO.C.x = Math.Max(R1.C.x, R2.C.x);
    RO.C.y = Math.Min(R1.C.y, R2.C.y);
    RO.B(x,y) and RO.D(x,y) = ....
    

    Inner rectangle RI:

    Swap Min and Max in above solution for overlapping rectangle RO.

提交回复
热议问题