New Posts  All Forums:Forum Nav:

Rectangle's in c#

post #1 of 22
Thread Starter 
hi guys is it possible ion c# (winforms) to add rectangles together?

say if rectangle a intersects with rectangle b they would form one rectangle with two parts a and b.
Mid range build
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k P8Z77-V ASUS ROG RX480 Corsair 8GB 2x 2GB + kingston hyperx 16gb 
Hard DriveOptical DriveCoolingOS
Samsung Evo SSD 500gb none corsair H80 windows 7 64 
MonitorPowerCaseMouse
Samsung s22b360 corsair tx 750 m NZXT phantom 410 (GM) logitech G400 
  hide details  
Reply
Mid range build
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k P8Z77-V ASUS ROG RX480 Corsair 8GB 2x 2GB + kingston hyperx 16gb 
Hard DriveOptical DriveCoolingOS
Samsung Evo SSD 500gb none corsair H80 windows 7 64 
MonitorPowerCaseMouse
Samsung s22b360 corsair tx 750 m NZXT phantom 410 (GM) logitech G400 
  hide details  
Reply
post #2 of 22
This?
Croissant
(15 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus Sabertooth Z77 GTX 680 2x4 gigs G-SKill 
Hard DriveOptical DriveCoolingOS
Crucial C300 2x Asus DVD-RW Silver Arrow Win 7 
MonitorPowerCaseAudio
Dual ASUS 24" Rosewill 750 Capstone Corsair Carbide Air 540 The Basic sound blaster Z-Series 
  hide details  
Reply
Croissant
(15 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus Sabertooth Z77 GTX 680 2x4 gigs G-SKill 
Hard DriveOptical DriveCoolingOS
Crucial C300 2x Asus DVD-RW Silver Arrow Win 7 
MonitorPowerCaseAudio
Dual ASUS 24" Rosewill 750 Capstone Corsair Carbide Air 540 The Basic sound blaster Z-Series 
  hide details  
Reply
post #3 of 22
Thread Starter 
Quote:
Originally Posted by Thereoncewasamaninparis View Post

This?

That is talking about the intersect method I know how to use that to a certain extent but I can not figure out how to add rectangles together.
Mid range build
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k P8Z77-V ASUS ROG RX480 Corsair 8GB 2x 2GB + kingston hyperx 16gb 
Hard DriveOptical DriveCoolingOS
Samsung Evo SSD 500gb none corsair H80 windows 7 64 
MonitorPowerCaseMouse
Samsung s22b360 corsair tx 750 m NZXT phantom 410 (GM) logitech G400 
  hide details  
Reply
Mid range build
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k P8Z77-V ASUS ROG RX480 Corsair 8GB 2x 2GB + kingston hyperx 16gb 
Hard DriveOptical DriveCoolingOS
Samsung Evo SSD 500gb none corsair H80 windows 7 64 
MonitorPowerCaseMouse
Samsung s22b360 corsair tx 750 m NZXT phantom 410 (GM) logitech G400 
  hide details  
Reply
post #4 of 22
Quote:
Originally Posted by ipv89 View Post

That is talking about the intersect method I know how to use that to a certain extent but I can not figure out how to add rectangles together.

I guess I am just not sure what you mean by "add" them together. Although creating an overloaded + operator for two rectangle objects would be fun if you're just wanting to create what would be an 8 sided polygon made up of two intersecting rectangles. But now that I said it, that sounds like what the intersect method does.
Croissant
(15 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus Sabertooth Z77 GTX 680 2x4 gigs G-SKill 
Hard DriveOptical DriveCoolingOS
Crucial C300 2x Asus DVD-RW Silver Arrow Win 7 
MonitorPowerCaseAudio
Dual ASUS 24" Rosewill 750 Capstone Corsair Carbide Air 540 The Basic sound blaster Z-Series 
  hide details  
Reply
Croissant
(15 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus Sabertooth Z77 GTX 680 2x4 gigs G-SKill 
Hard DriveOptical DriveCoolingOS
Crucial C300 2x Asus DVD-RW Silver Arrow Win 7 
MonitorPowerCaseAudio
Dual ASUS 24" Rosewill 750 Capstone Corsair Carbide Air 540 The Basic sound blaster Z-Series 
  hide details  
Reply
post #5 of 22
Thread Starter 
yeah I didn't explain it very well rolleyes.gif

I want to add them together like the way snake grows in that old mobile game.
Mid range build
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k P8Z77-V ASUS ROG RX480 Corsair 8GB 2x 2GB + kingston hyperx 16gb 
Hard DriveOptical DriveCoolingOS
Samsung Evo SSD 500gb none corsair H80 windows 7 64 
MonitorPowerCaseMouse
Samsung s22b360 corsair tx 750 m NZXT phantom 410 (GM) logitech G400 
  hide details  
Reply
Mid range build
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k P8Z77-V ASUS ROG RX480 Corsair 8GB 2x 2GB + kingston hyperx 16gb 
Hard DriveOptical DriveCoolingOS
Samsung Evo SSD 500gb none corsair H80 windows 7 64 
MonitorPowerCaseMouse
Samsung s22b360 corsair tx 750 m NZXT phantom 410 (GM) logitech G400 
  hide details  
Reply
post #6 of 22
Yeh, I think an overloaded + operator for rectangles will be necessary. I will definitely look at it because I am at work and have nothing to do, yeahhhhhhh.
Croissant
(15 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus Sabertooth Z77 GTX 680 2x4 gigs G-SKill 
Hard DriveOptical DriveCoolingOS
Crucial C300 2x Asus DVD-RW Silver Arrow Win 7 
MonitorPowerCaseAudio
Dual ASUS 24" Rosewill 750 Capstone Corsair Carbide Air 540 The Basic sound blaster Z-Series 
  hide details  
Reply
Croissant
(15 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus Sabertooth Z77 GTX 680 2x4 gigs G-SKill 
Hard DriveOptical DriveCoolingOS
Crucial C300 2x Asus DVD-RW Silver Arrow Win 7 
MonitorPowerCaseAudio
Dual ASUS 24" Rosewill 750 Capstone Corsair Carbide Air 540 The Basic sound blaster Z-Series 
  hide details  
Reply
post #7 of 22
So it looks like you can't overload any operators since the Rectangle class doesn't have any boolean operators so you just have to create a new method.
Code:
Rectangle rec1 = ...
Rectangle rec2 = ...

//Since you will have at most, eight distinct points
Point[] pointSet = new Point[8];

//Since you don't want to combine them if they don't intersect
if(Rectangle.Intersect(rec1,rec2))
{
      pointSet =  combine(Rectangle rec1, Rectangle rec2);
      //Apparently you can't wipe specific "drawn" objects from the graphics object
      graphic.Clear(Color.White);
      graphic.DrawPolygon(new Pen(new SolidBrush(Color.Black)), pointSet );
}

public static Point[] combine(Rectangle r1, Rectangle r2)
{
      Point[] pointSet = new Point[8]'
      //
      // All the good stuff
      //
      return pointSet;
}


Now here is your problem, as soon as you combine those two rectangles(unless they lined up just right) you will no longer have a rectangle, you will have a polygon. So the next time you're going to be combining a polygon with a rectangle, plus it could be twelve points that have to be drawn.
Code:
public static Point[] combine(Point[] p, Rectangle r2)
{
      Point[] pointSet = new Point[12]'
      //
      // All the good stuff
      //
      return pointSet;
}

At this point the program crashes since you only allocated enough memory(plus a small buffer) for 8 points in the pointSet.
Edited by Thereoncewasamaninparis - 5/28/13 at 10:11am
Croissant
(15 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus Sabertooth Z77 GTX 680 2x4 gigs G-SKill 
Hard DriveOptical DriveCoolingOS
Crucial C300 2x Asus DVD-RW Silver Arrow Win 7 
MonitorPowerCaseAudio
Dual ASUS 24" Rosewill 750 Capstone Corsair Carbide Air 540 The Basic sound blaster Z-Series 
  hide details  
Reply
Croissant
(15 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus Sabertooth Z77 GTX 680 2x4 gigs G-SKill 
Hard DriveOptical DriveCoolingOS
Crucial C300 2x Asus DVD-RW Silver Arrow Win 7 
MonitorPowerCaseAudio
Dual ASUS 24" Rosewill 750 Capstone Corsair Carbide Air 540 The Basic sound blaster Z-Series 
  hide details  
Reply
post #8 of 22
Thread Starter 
Mmmm I see thank you for that information I think it might be easyr to use a class to create a rectangle than store it in an array.
Mid range build
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k P8Z77-V ASUS ROG RX480 Corsair 8GB 2x 2GB + kingston hyperx 16gb 
Hard DriveOptical DriveCoolingOS
Samsung Evo SSD 500gb none corsair H80 windows 7 64 
MonitorPowerCaseMouse
Samsung s22b360 corsair tx 750 m NZXT phantom 410 (GM) logitech G400 
  hide details  
Reply
Mid range build
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k P8Z77-V ASUS ROG RX480 Corsair 8GB 2x 2GB + kingston hyperx 16gb 
Hard DriveOptical DriveCoolingOS
Samsung Evo SSD 500gb none corsair H80 windows 7 64 
MonitorPowerCaseMouse
Samsung s22b360 corsair tx 750 m NZXT phantom 410 (GM) logitech G400 
  hide details  
Reply
post #9 of 22
So basically if

Rectangle1 is 100x100 pixels wide, and it hits Rectangle2, which is 50x50 pixels wide, it should turn into a 150x150 rectangle or something?
Computah
(18 items)
 
  
CPUMotherboardGraphicsRAM
2500k @4.5 Asus P8Z68-V GEN3 MSI 770GTX Twin Frozr Gaming 2x4Gb Ripjaws X 
Hard DriveHard DriveCoolingOS
2x HyperX Fury 240gb Raid0 WD Red 3TB NH-D14 Windows 10 Pro 64b 
MonitorMonitorKeyboardPower
Acer X233H 23" BenQ G2420HDB 24" Ducky Shine 3 TKL Corsair TX 750 
CaseMouseMouse PadAudio
HAF 912 PLUS Logitech G400s Roccat Taito Beyerdynamic DT-770 Pro 80ohm 
  hide details  
Reply
Computah
(18 items)
 
  
CPUMotherboardGraphicsRAM
2500k @4.5 Asus P8Z68-V GEN3 MSI 770GTX Twin Frozr Gaming 2x4Gb Ripjaws X 
Hard DriveHard DriveCoolingOS
2x HyperX Fury 240gb Raid0 WD Red 3TB NH-D14 Windows 10 Pro 64b 
MonitorMonitorKeyboardPower
Acer X233H 23" BenQ G2420HDB 24" Ducky Shine 3 TKL Corsair TX 750 
CaseMouseMouse PadAudio
HAF 912 PLUS Logitech G400s Roccat Taito Beyerdynamic DT-770 Pro 80ohm 
  hide details  
Reply
post #10 of 22
Quote:
Originally Posted by pepejovi View Post

So basically if

Rectangle1 is 100x100 pixels wide, and it hits Rectangle2, which is 50x50 pixels wide, it should turn into a 150x150 rectangle or something?

...minus whatever intersects.
Croissant
(15 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus Sabertooth Z77 GTX 680 2x4 gigs G-SKill 
Hard DriveOptical DriveCoolingOS
Crucial C300 2x Asus DVD-RW Silver Arrow Win 7 
MonitorPowerCaseAudio
Dual ASUS 24" Rosewill 750 Capstone Corsair Carbide Air 540 The Basic sound blaster Z-Series 
  hide details  
Reply
Croissant
(15 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus Sabertooth Z77 GTX 680 2x4 gigs G-SKill 
Hard DriveOptical DriveCoolingOS
Crucial C300 2x Asus DVD-RW Silver Arrow Win 7 
MonitorPowerCaseAudio
Dual ASUS 24" Rosewill 750 Capstone Corsair Carbide Air 540 The Basic sound blaster Z-Series 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming