collision


Namecollision JSON
Version 1.2.2 PyPI version JSON
download
home_pagehttps://github.com/QwekoDev/collision/
SummaryCollision is a python library meant for collision detection between convex and concave polygons, circles, and points.
upload_time2018-10-17 02:29:23
maintainer
docs_urlNone
authorqwertyquerty
requires_python>=2.7
licenseMIT
keywords python collision detection polygon concave convex circle physics game
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # collision.py

## Info

Collision is a python library meant for collision detection between convex and concave polygons, circles, and points.

### Insallation

To get the latest stable version:

`pip install collision`

Or to get the latest development version:

`pip install https://github.com/QwekoDev/collision/archive/master.zip`

## Classes

### ***class*** `collision.Vector(x, y)`

A 2D vector/point class

**Properties:**

- `x` *(int) or (float)* - The x-coordinate
- `y` *(int) or (float)* - The y-coordinate

**Methods:**

##### *func* `copy()` → `collision.vec`

Return a copy of the vector

##### *func* `set(v)`

Copy another vectors values onto the vector

- `v` *(collision.vec)* - The vector to copy from

##### *func* `perp()` → `collision.vec`

Return the vector rotated perpandicularly

##### *func* `rotate(angle)` → `collision.vec`

Return the vector rotated the angle

- `angle` *(int) or (float)* - Radians to rotate the point

##### *func* `reverse()` → `collision.vec`

Return a reversed version of the vector

##### *func* `normalize()` → `collision.vec`

Return a normalized version of the vector

##### *func* `project(v)` → `collision.vec`

Return the vector projected onto the passed vector

- `v` *(collision.vec)* - The vector to project upon

##### *func* `project_n(v)` → `collision.vec`

Return the vector projected onto a unit vector

- `v` *(collision.vec)* - The vector to project upon

##### *func* `reflect(axis)` → `collision.vec`

Return the vector reflected upon the passed axis vector

- `axis` *(collision.vec)* - The axis to reflect upon

##### *func* `reflect_n(axis)` → `collision.vec`

Return the vector reflected upon the passed axis unit vector

- `axis` *(collision.vec)* - The axis to reflect upon

##### *func* `dot(v)` → `int or float`

Returns the dot product of the vector and another

- `v` *(collision.vec)* - The other vector for the dot product

##### *func* `ln()` → `int or float`

Returns the length of the vector

##### *func* `ln2()` → `int or float`

Returns the squared length of the vector

------

### ***class*** `collision.Circle(pos, radius)`

A simple circle with a position and radius

**Properties:**

- `pos` *(collision.vec)* - The center coordinate of the circle
- `radius` *(int) or (float)* - The radius of the circle

**Methods:**

##### *func* `get_aabb()` → `collision.Poly`

Returns the AABB bounding box of the circle

------

### ***class*** `collision.Poly(pos, points, angle = 0)`

A **convex** polygon with a position, a list of points relative to that position, and an angle

**Properties:**

- `pos` *(collision.vec)* - The center coordinate of the circle
- `points` *(list[collision.vec])* - A list of absolute points (each relative point + the position of the polygon.) Can not be directly edited.
- `rel_points` *(list[collision.vec])* - A list of points relative to the position. This property should not be directly changed.
- `angle` *(int) or (float)* - The angle which the polygon is rotated. Changing this will cause the polygon to be recalculated.

**Class Methods:**

##### *func* `Poly.from_box(pos, width, height)` → `collision.Poly`

Creates a polygon from

- `pos` *(collision.vec)* - The center coordinate of the polygon/box
- `width` *(int) or (float)* - The width of the box
- `height` *(int) or (float)* - The height of the box

**Methods:**

##### *func* `aabb()` → `collision.Poly`

Returns the AABB bounding box of the polygon

##### *func* `set_points(points)`

Change the base points relative to the position. After this is done, the polygon will be recalculated again. Angle will be preserved. Use this instead of editing the `points` property.

##### *func* `get_centroid()` → `collision.vec`

Get the centroid of the polygon. The arithmatic mean of all of the points.


------

### ***class*** `collision.Concave_Poly(pos, points, angle = 0)`

A **concave** polygon with a position, a list of points relative to that position, and an angle. This takes longer to collide than a regular `Poly` does, so only use this if your shape must be concave.

**Properties:**

- `pos` *(collision.vec)* - The center coordinate of the circle
- `points` *(list[collision.vec])* - A list of absolute points (each relative point + the position of the polygon.) Can not be directly edited.
- `rel_points` *(list[collision.vec])* - A list of points relative to the position. This property should not be directly changed.
- `tris` *(list[collision.Poly])* - A list of triangles relative to the position on the poly that make up the concave polygon. Used for concave collisions.
- `angle` *(int) or (float)* - The angle which the polygon is rotated. Changing this will cause the polygon to be recalculated.


**Methods:**

##### *func* `aabb()` → `collision.Concave_Poly`

Returns the AABB bounding box of the polygon

##### *func* `set_points(points)`

Change the base points relative to the position. After this is done, the polygon will be recalculated again. Angle will be preserved. Use this instead of editing the `points` property.

##### *func* `get_centroid()` → `collision.vec`

Get the centroid of the polygon. The arithmatic mean of all of the points.


------

### ***class*** `collision.Response()`

The result of a collision between two objects. May optionally be passed to collision tests to retrieve additional information. At its cleared state, it may seem to have odd values. Ignore these, they are just there to make generating the response more efficient. The response should be ignored unless there is a successful collision.

**Properties:**

- `a` *(collision shape)* - The first object in the collision test
- `b` *(collision shape)* - The second object in the collision test
- `overlap` *(int) or (float)* - Magnitude of the overlap on the shortest colliding axis
- `overlap_n` *(collision.vec)* - The shortest colliding axis (unit vector)
- `overlap_v` *(collision.vec)* - The overlap vector. If this is subtracted from the position of `a`, `a` and `b` will no longer be colliding.
- `a_in_b` *(bool)* - Whether `a` is fully inside of `b`
- `b_in_a` *(bool)* - Whether `b` is fully inside of `a`

**Methods:**

##### *func* `clear()` → `collision.Response`

Clears the Response for re-use, and returns itself

# To be finished
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/QwekoDev/collision/",
    "name": "collision",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.7",
    "maintainer_email": "",
    "keywords": "python collision detection polygon concave convex circle physics game",
    "author": "qwertyquerty",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/f4/52/e9325e5dcfac12e3047bbcdb3e15d3c5a3b53c52712cb0abb8ec5e06602d/collision-1.2.2.tar.gz",
    "platform": "Windows",
    "description": "# collision.py\n\n## Info\n\nCollision is a python library meant for collision detection between convex and concave polygons, circles, and points.\n\n### Insallation\n\nTo get the latest stable version:\n\n`pip install collision`\n\nOr to get the latest development version:\n\n`pip install https://github.com/QwekoDev/collision/archive/master.zip`\n\n## Classes\n\n### ***class*** `collision.Vector(x, y)`\n\nA 2D vector/point class\n\n**Properties:**\n\n- `x` *(int) or (float)* - The x-coordinate\n- `y` *(int) or (float)* - The y-coordinate\n\n**Methods:**\n\n##### *func* `copy()` → `collision.vec`\n\nReturn a copy of the vector\n\n##### *func* `set(v)`\n\nCopy another vectors values onto the vector\n\n- `v` *(collision.vec)* - The vector to copy from\n\n##### *func* `perp()` → `collision.vec`\n\nReturn the vector rotated perpandicularly\n\n##### *func* `rotate(angle)` → `collision.vec`\n\nReturn the vector rotated the angle\n\n- `angle` *(int) or (float)* - Radians to rotate the point\n\n##### *func* `reverse()` → `collision.vec`\n\nReturn a reversed version of the vector\n\n##### *func* `normalize()` → `collision.vec`\n\nReturn a normalized version of the vector\n\n##### *func* `project(v)` → `collision.vec`\n\nReturn the vector projected onto the passed vector\n\n- `v` *(collision.vec)* - The vector to project upon\n\n##### *func* `project_n(v)` → `collision.vec`\n\nReturn the vector projected onto a unit vector\n\n- `v` *(collision.vec)* - The vector to project upon\n\n##### *func* `reflect(axis)` → `collision.vec`\n\nReturn the vector reflected upon the passed axis vector\n\n- `axis` *(collision.vec)* - The axis to reflect upon\n\n##### *func* `reflect_n(axis)` → `collision.vec`\n\nReturn the vector reflected upon the passed axis unit vector\n\n- `axis` *(collision.vec)* - The axis to reflect upon\n\n##### *func* `dot(v)` → `int or float`\n\nReturns the dot product of the vector and another\n\n- `v` *(collision.vec)* - The other vector for the dot product\n\n##### *func* `ln()` → `int or float`\n\nReturns the length of the vector\n\n##### *func* `ln2()` → `int or float`\n\nReturns the squared length of the vector\n\n------\n\n### ***class*** `collision.Circle(pos, radius)`\n\nA simple circle with a position and radius\n\n**Properties:**\n\n- `pos` *(collision.vec)* - The center coordinate of the circle\n- `radius` *(int) or (float)* - The radius of the circle\n\n**Methods:**\n\n##### *func* `get_aabb()` → `collision.Poly`\n\nReturns the AABB bounding box of the circle\n\n------\n\n### ***class*** `collision.Poly(pos, points, angle = 0)`\n\nA **convex** polygon with a position, a list of points relative to that position, and an angle\n\n**Properties:**\n\n- `pos` *(collision.vec)* - The center coordinate of the circle\n- `points` *(list[collision.vec])* - A list of absolute points (each relative point + the position of the polygon.) Can not be directly edited.\n- `rel_points` *(list[collision.vec])* - A list of points relative to the position. This property should not be directly changed.\n- `angle` *(int) or (float)* - The angle which the polygon is rotated. Changing this will cause the polygon to be recalculated.\n\n**Class Methods:**\n\n##### *func* `Poly.from_box(pos, width, height)` → `collision.Poly`\n\nCreates a polygon from\n\n- `pos` *(collision.vec)* - The center coordinate of the polygon/box\n- `width` *(int) or (float)* - The width of the box\n- `height` *(int) or (float)* - The height of the box\n\n**Methods:**\n\n##### *func* `aabb()` → `collision.Poly`\n\nReturns the AABB bounding box of the polygon\n\n##### *func* `set_points(points)`\n\nChange the base points relative to the position. After this is done, the polygon will be recalculated again. Angle will be preserved. Use this instead of editing the `points` property.\n\n##### *func* `get_centroid()` → `collision.vec`\n\nGet the centroid of the polygon. The arithmatic mean of all of the points.\n\n\n------\n\n### ***class*** `collision.Concave_Poly(pos, points, angle = 0)`\n\nA **concave** polygon with a position, a list of points relative to that position, and an angle. This takes longer to collide than a regular `Poly` does, so only use this if your shape must be concave.\n\n**Properties:**\n\n- `pos` *(collision.vec)* - The center coordinate of the circle\n- `points` *(list[collision.vec])* - A list of absolute points (each relative point + the position of the polygon.) Can not be directly edited.\n- `rel_points` *(list[collision.vec])* - A list of points relative to the position. This property should not be directly changed.\n- `tris` *(list[collision.Poly])* - A list of triangles relative to the position on the poly that make up the concave polygon. Used for concave collisions.\n- `angle` *(int) or (float)* - The angle which the polygon is rotated. Changing this will cause the polygon to be recalculated.\n\n\n**Methods:**\n\n##### *func* `aabb()` → `collision.Concave_Poly`\n\nReturns the AABB bounding box of the polygon\n\n##### *func* `set_points(points)`\n\nChange the base points relative to the position. After this is done, the polygon will be recalculated again. Angle will be preserved. Use this instead of editing the `points` property.\n\n##### *func* `get_centroid()` → `collision.vec`\n\nGet the centroid of the polygon. The arithmatic mean of all of the points.\n\n\n------\n\n### ***class*** `collision.Response()`\n\nThe result of a collision between two objects. May optionally be passed to collision tests to retrieve additional information. At its cleared state, it may seem to have odd values. Ignore these, they are just there to make generating the response more efficient. The response should be ignored unless there is a successful collision.\n\n**Properties:**\n\n- `a` *(collision shape)* - The first object in the collision test\n- `b` *(collision shape)* - The second object in the collision test\n- `overlap` *(int) or (float)* - Magnitude of the overlap on the shortest colliding axis\n- `overlap_n` *(collision.vec)* - The shortest colliding axis (unit vector)\n- `overlap_v` *(collision.vec)* - The overlap vector. If this is subtracted from the position of `a`, `a` and `b` will no longer be colliding.\n- `a_in_b` *(bool)* - Whether `a` is fully inside of `b`\n- `b_in_a` *(bool)* - Whether `b` is fully inside of `a`\n\n**Methods:**\n\n##### *func* `clear()` → `collision.Response`\n\nClears the Response for re-use, and returns itself\n\n# To be finished",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Collision is a python library meant for collision detection between convex and concave polygons, circles, and points.",
    "version": "1.2.2",
    "project_urls": {
        "Homepage": "https://github.com/QwekoDev/collision/"
    },
    "split_keywords": [
        "python",
        "collision",
        "detection",
        "polygon",
        "concave",
        "convex",
        "circle",
        "physics",
        "game"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f452e9325e5dcfac12e3047bbcdb3e15d3c5a3b53c52712cb0abb8ec5e06602d",
                "md5": "356f08e7f8e5fe9fc946f5ad4e3f4c34",
                "sha256": "366b2619e0eb341116f0c461bd933543c6d0b3274c42ac3ebd604972b7335683"
            },
            "downloads": -1,
            "filename": "collision-1.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "356f08e7f8e5fe9fc946f5ad4e3f4c34",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7",
            "size": 8727,
            "upload_time": "2018-10-17T02:29:23",
            "upload_time_iso_8601": "2018-10-17T02:29:23.210887Z",
            "url": "https://files.pythonhosted.org/packages/f4/52/e9325e5dcfac12e3047bbcdb3e15d3c5a3b53c52712cb0abb8ec5e06602d/collision-1.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2018-10-17 02:29:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "QwekoDev",
    "github_project": "collision",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "collision"
}
        
Elapsed time: 0.25577s