简体   繁体   中英

Split a Rectangle into n equal Parts

I need to split a rectangle Rect Structure, Rect(Double X, Double Y, Double Width, Double Height) into a number of smaller rectangles/structures for n = 2, n= 4 and n = 6, i define a Rect for my Diagram (Nodes and Links) that bounds the whole Diagram

Rect b = activeDiagram.Panel.DiagramBounds;

Can someone provide an example of doing it with my structure in C#?

I'm not 100% sure I understand your question completely, but is it as simple as slicing it up in one direction?

Rect[] smallerRects = new Rect[n];
for(int i = 0;i < n;++i)
   smallerRects[i] = new Rect(b.X + b.Width / n * i, b.Y, b.Width / n, b.Height);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM