Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # for Ellipse class, assuming rotation increases in clockwise direction (negate rotation if not!)
- # UNTESTED!
- containsPoint: (p, withRotation=true) ->
- # "ellipse space" is the cartesian space
- # where the ellipse becomes the unit
- # circle centered at (0, 0)
- [x, y] = [p.x - @x, p.y - @y] # translate point into ellipse space
- if withRotation and @rotation # optionally rotate point into ellipse space
- c = Math.cos(@rotation)
- s = Math.sin(@rotation)
- [x, y] = [x*c + y*s, y*c + x*s]
- x = x / @width # scale point into ellipse space
- y = y / @height
- x*x + y*y <= 1 #if the resulting point falls on/in the unit circle at 0, 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement