Hallo,
habe folgendes Problem... unzwar soll ich das Schnittrecheck zweier Rechecke berechnen...
jeder ohne die Verwendung von Bibliotheken... also auch ohne intersection...
hier mein bisheriger code jedoch mit intersection damit überhaupt was funktioniert ^^
Danke schon mal
habe folgendes Problem... unzwar soll ich das Schnittrecheck zweier Rechecke berechnen...
jeder ohne die Verwendung von Bibliotheken... also auch ohne intersection...
hier mein bisheriger code jedoch mit intersection damit überhaupt was funktioniert ^^
Java:
package grafik2;
import java.awt.*;
import javax.swing.*;
public class test extends JPanel {
public void paintComponent( Graphics g ){
int x = 50;
int y = 50;
int width = 150;
int height = 150;
Rectangle r1 = new Rectangle(x, y, width, height);
Rectangle r2 = new Rectangle(x+100, y+100, width-65, height-65);
//rechteck 1
Graphics2D g2 = (Graphics2D)g;
g2.setColor( new Color( 20, 0, 200 ) );
g2.fill( r1 );
g2.setColor( new Color( 255, 48, 48 ) );
g2.fill( r2 );
g.setColor( Color.MAGENTA );
Rectangle x1 = r1.intersection(r2);
if(x1.width > 0)
{
g2.draw( x1 );
g.fillRect(x1.x, x1.y, x1.width, x1.height);
System.out.println(x1);
}
}
public static void main( String[] args ){
test e = new test();
JFrame f = new JFrame( "Quadrat" );
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.setSize( 450, 450 );
f.add( e );
f.setVisible( true );
}
}
Danke schon mal