ios - Calculate angle for points of circle that intersect with rect -


i start saying not terribly skilled in maths. please excuse if problem seems trivial you, cant quite wrap head around it.

i need distribute , align views on circle given radius , center. no problem , have working great. can specify maximum , minimum angle alignment circle, views distributes on half-circle or similar.

to provide better insight, here code:

    var minangle: double = 270     var maxangle: double = 630     var = 0     let maxindizes = isfullcircle(minangle, maxangle: maxangle) ? subviews.count : subviews.count - 1      subviews.foreach { (subview: uiview) -> () in         let angle = getangleforindex(i, max: maxindizes, minangle: minangle, maxangle: maxangle)         let radius = double(bounds.width / 2)         let circlepos = getpointforangle(angle, radius: radius)          let view = uiview()         addsubview(view)         view.center = circlepos          i++     } 

the problem is, of views have in given rectangle. depending on center of circle, views might placed outside of rectangle , thus, offscreen.

to fix problem trying use semi circle if full circle not fit inside rectangle. said code works using semi circles specifying different minangle or maxangle. problem have no idea on how calculate minangle , maxangle semi circle fits rectangle.

to further clarify problem, tried illustrating it:

illustration

tl;dr: need calculate angle intersections between rectangle , circle marked arrows.

additional information:

  • the circles diameter less rectangles width or height
  • the app targeting ios 9
  • any code written in swift 2, may require xcode 7

let's circle center (cx, cy), raidus r, , top-left , right-bottom corners of rectangle (x1,y1)-(x2,y2)

solve equations (this 1 left edge of rectangle)

(x1-cx)^2 + (y-cy)^2 = r^2 

if solution y exists, check whether y found (one or 2 solutions) in range [y1..y2]. if so, calculate angle intersection

fi = atan2(y-cy, x1-cx) 

Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -