class Eagle::Physics2D::Polygon

Overview

A convex polygon collision shape. Points can be in either winding order. Concave input isn't supported; split it into several convex polygons.

Physics2D::Polygon.box(32, 48)
Physics2D::Polygon.new([v2(0, -20), v2(15, 10), v2(-15, 10)]) # triangle

Defined in:

eagle/physics/shapes2d.cr

Constructors

Instance Method Summary

Instance methods inherited from class Eagle::Physics2D::Shape

aabb : Rect aabb, area : Float32 area, inertia_factor : Float32 inertia_factor, local_aabb : Rect local_aabb, offset : Vec2 offset, offset=(offset : Vec2) offset=, transformed(t : Transform2D) : Shape transformed

Constructor Detail

def self.box(w : Number, h : Number, offset : Vec2 = Vec2::ZERO) : Polygon #

A w by h box centered on offset.


def self.new(points : Array(Vec2), offset : Vec2 = Vec2::ZERO) #

Creates a polygon from convex points.


def self.regular(sides : Int32, radius : Number, offset : Vec2 = Vec2::ZERO) : Polygon #

A regular polygon with sides corners.


Instance Method Detail

def aabb : Rect #

Bounds in world space.


def area : Float32 #

Area of the polygon.


def centroid : Vec2 #

The polygon's center of mass.


def contains?(p : Vec2) : Bool #

True when p is inside the polygon.


def inertia_factor : Float32 #

Inertia per unit mass.


def local_aabb : Rect #

Bounds in local space.


def normals : Array(Vec2) #

Outward edge normals.


def points : Array(Vec2) #

Vertices in local space, stored clockwise.


def support(d : Vec2) : Vec2 #

The vertex furthest in direction d, used by collision tests.


def transformed(t : Transform2D) : Shape #

A world-space copy.