Java Line Intersect intersects(int x0, int y0, int w0, int h0, int x, int y, int w, int h)

Here you can find the source of intersects(int x0, int y0, int w0, int h0, int x, int y, int w, int h)

Description

Test to see if two rectangles intersect

License

Open Source License

Parameter

Parameter Description
x0 the first point x, top left
y0 the first point y, top left
w0 the first rec width
h0 the first rec height
x the second point x, top left
y the second point y, top left
w h the second rec width
h the second rec height

Return

true if rectangles intersect

Declaration

public static boolean intersects(int x0, int y0, int w0, int h0, int x,
        int y, int w, int h) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   ww  w  .ja v  a 2  s. c  o m
     * Test to see if two rectangles intersect
     * @param x0 the first point x, top left
     * @param y0 the first point y, top left
     * @param w0 the first rec width
     * @param h0 the first rec height
     * @param x the second point x, top left
     * @param y the second point y, top left
     * @param w h the second rec width
     * @param h the second rec height
     * @return true if rectangles intersect
     */
    public static boolean intersects(int x0, int y0, int w0, int h0, int x,
            int y, int w, int h) {
        if (w0 <= 0 || h0 <= 0 || w <= 0 || h <= 0) {
            return false;
        }
        return (x + w > x0 && y + h > y0 && x < x0 + w0 && y < y0 + h0);

    }
}

Related

  1. intersectLines(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double[] point)
  2. intersectLineSegments(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
  3. intersectLinesWithParams(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double[] params)
  4. intersects(int b1, int e1, int b2, int e2)
  5. intersects(int start1, int length1, int start2, int length2)