eonist / Cube

Convert perspective square to perspective cube

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mit platform platform Lang Carthage compatible codebeat badge

Cube

img

What is it

Convert perspective square to perspective cube

How does it work

  • Finds perspective vanishing points
  • Uses law of ratios to find correct volume
  • Returns 2d-Points of the cube bounds

How do I get it

  • Carthage github "eonist/Cube"
  • Manual Open Cube.xcodeproj
  • CocoaPod (Coming soon)

Example:

let corners:[CGPoint] = [.init(x:100,y:130),.init(x:220,y:150),.init(x:200,y:220),.init(x:130,y:240)]
let quad:Quad = (corners[0],corners[1],corners[3],corners[2])
let cube:Cube = CubeUtil.cube(quad:quad)
let cubeGraphic:CubeGraphic = .init()
layer.addSublayer(cubeGraphic)
cubeGraphic.drawCube(cube: cube)

References:

Todo:

  • Add support for 1 point perspective Quadrilaterals βœ…
  • Add support for horizontal 1p quads (co-linear, epsilon etc) βœ…
  • Add support for square w/o perspective βœ…
  • Optimize the math for performance πŸ‘ˆ
  • Account for object relation to POV πŸ‘ˆ

About

Convert perspective square to perspective cube


Languages

Language:Swift 97.3%Language:Objective-C 2.7%