rectangles

Get bounds of unrotated rotated rectangle

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 03:23:22
I have a rectangle that has a rotation already applied to it. I want to get the the unrotated dimensions (the x, y, width, height). Here is the dimensions of the element currently: Bounds at a 90 rotation: { height 30 width 0 x 25 y 10 } Here are the dimensions after the rotation is set to none: Bounds at rotation 0 { height 0 width 30 x 10 y 25 } In the past, I was able to set the rotation to 0 and then read the updated bounds . However, there is a bug in one of the functions I was using, so now I have to do it manually. Is there a simple formula to get the bounds at rotation 0 using the info

What is the best way to convert from a RectF to a Rect in Android?

假如想象 提交于 2019-12-04 00:06:17
问题 I would like to convert from a RectF to a Rect in Android. Currently I have: RectF rectF = new RectF(); rectF.set( ... some values ... ); ... Rect rect = new Rect((int)rectF.left, (int)rectF.top, (int)rectF.right, (int)rectF.bottom)); Is there a better way? 回答1: Ah ha -- found the answer: rectF.round(rect); -- or -- rectF.roundOut(rect); 来源: https://stackoverflow.com/questions/16449145/what-is-the-best-way-to-convert-from-a-rectf-to-a-rect-in-android

Merging and splitting overlapping rectangles to produce non-overlapping ones

我只是一个虾纸丫 提交于 2019-12-03 17:20:37
I am looking for an algorithm as follows: Given a set of possibly overlapping rectangles (All of which are "not rotated", can be uniformly represented as (left,top,right,bottom) tuplets, etc...), it returns a minimal set of (non-rotated) non-overlapping rectangles, that occupy the same area. It seems simple enough at first glance, but prooves to be tricky (at least to be done efficiently). Are there some known methods for this/ideas/pointers? Methods for not necessarily minimal, but heuristicly small, sets, are interesting as well, so are methods that produce any valid output set at all.

How to find the nearest point in the perimeter of a rectangle to a given point?

妖精的绣舞 提交于 2019-12-03 15:48:51
This is a language-agnostic question. Given a rectangle's dimensions with l,t,w,h (left, top, width, height) and a point x,y , how do I find the nearest point on the perimeter of the rectangle to that point? I have tried to resolve it in Lua, but any other language would do. So far this is my best effort: local function nearest(x, a, b) if a <= x and x <= b then return x elseif math.abs(a - x) < math.abs(b - x) then return a else return b end end local function getNearestPointInPerimeter(l,t,w,h, x,y) return nearest(x, l, l+w), nearest(y, t, t+h) end This works for a point outside of the

How create a screenshot of a particular area?

半世苍凉 提交于 2019-12-03 13:17:53
I have code that receives a specific area already defined before on server side and creates a hole on Form in client side. Instead of this, i want to get a screen capture of this same area but without appears my Form in final result, like a normal desktop capture, but in this case will be only captured, this small area. So, how i can adapt this my code below for this? procedure TForm1.CS1Read(Sender: TObject; Socket: TCustomWinSocket); var X1, X2, Y1, Y2: Integer; List: TStrings; FormRegion, HoleRegion: HRGN; StrCommand: String; begin StrCommand := Socket.ReceiveText; if Pos('§', StrCommand) >

How to divide a set of overlapping ranges into non-overlapping ranges?

*爱你&永不变心* 提交于 2019-12-03 11:55:57
Let's say you have a set of ranges: 0 - 100: 'a' 0 - 75: 'b' 95 - 150: 'c' 120 - 130: 'd' Obviously, these ranges overlap at certain points. How would you dissect these ranges to produce a list of non-overlapping ranges, while retaining information associated with their original range (in this case, the letter after the range)? For example, the results of the above after running the algorithm would be: 0 - 75: 'a', 'b' 76 - 94: 'a' 95 - 100: 'a', 'c' 101 - 119: 'c' 120 - 130: 'c', 'd' 131 - 150: 'c' I had the same question when writing a program to mix (partly overlapping) audio samples. What

What's a good, simple, 2D rectangles-only collision detection algorithm?

一世执手 提交于 2019-12-03 10:42:08
I'm designing a collision detection game tutorial for young adults, so I want this to be as simple as possible to make it easier to explain. The requirements are very simple. The world is 2D and contains only rectangles (of arbitrary sizes). BSP and even quadtrees seems like it would be overkill (again, the emphasis is on simplicity) but I would like something more efficient than brute forcing through all n(n-1)/2 possible collisions. 2D, rectangles only, and simple. Can anyone point to an algorithm I can look up? Is a quadtree algorithm what I'm looking for? EDIT: Also, the rectangles will

How to draw a rounded rectangle (rectangle with rounded corners) with OpenCV?

☆樱花仙子☆ 提交于 2019-12-03 10:28:58
问题 How can I draw a rectangle with rounded corners in OpenCV? I know that the functions ellipse() and line() can be simply put together to draw it. I just wonder if someone has done it before and has put it in a proper function so I can use it? Ideally the corner radius is to calibrate in a parameter. I searched a lot for that, but it seems no one had that problem before. If no one has such I function I will probably post my own solution here in a few days. 回答1: I realized, this is much easier

Drawing Rectangles in iOS

ぐ巨炮叔叔 提交于 2019-12-03 09:34:55
问题 My goal for my app is for the user to be able to sort through different scheduling options by swiping to the left and right of an iPhone screen. How would I draw and remove rectangles as the user sorts through these different scheduling options? I have a UIViewController.h, UIViewController.m, and UIViewController.xib files to manipulate. Do I need a separate UIView class? If so, how do I connect that UIView class to the view in my .xib file? 回答1: Wow... so many complicated solution, here is

How to compute the union polygon of two (or more) rectangles

筅森魡賤 提交于 2019-12-03 09:06:47
For example we have two rectangles and they overlap. I want to get the exact range of the union of them. What is a good way to compute this? These are the two overlapping rectangles. Suppose the cords of vertices are all known: How can I compute the cords of the vertices of their union polygon? And what if I have more than two rectangles? There exists a Line Sweep Algorithm to calculate area of union of n rectangles. Refer the link for details of the algorithm. As said in article, there exist a boolean array implementation in O(N^2) time. Using the right data structure (balanced binary search