首页 \ 问答 \ 找到旋转矩形的边界矩形[重复](Find the Bounding Rectangle of Rotated Rectangle [duplicate])

找到旋转矩形的边界矩形[重复](Find the Bounding Rectangle of Rotated Rectangle [duplicate])

这个问题在这里已有答案:

我有坐标(x1,y1)和(x2,y2)的矩形,我必须使用旋转矩阵将矩形围绕它旋转一个θ

 |  cosθ  sinθ |
 | -sinθ  cosθ |

我需要在旋转后找到边界矩形的坐标。

轮换前

0,0
 |"""""""""""""""""""""""""""""""""""""""""""|
 |                                           |
 |  x1,y1                                    |
 |       |"""""""""""""|                     |
 |       |             |                     |
 |       |             |                     | 
 |       |             |                     |
 |       """""""""""""" x2,y2                |
 |                                           |
 |                                           |
  """"""""""""""""""""""""""""""""""""""""""" W,H

轮换后

 0,0
     |"""""""""""""""""""""""""""""""""""""""""""|
     |           ?,?                             |
     |            |""""/\"""""|                  |      
     |            |   /   \   |                  |
     |            |  /      \ |                  |
     |            | /        /|                  |
     |            |/        / |                  |
     |            |\       /  |                  |
     |            |  \    /   |                  |
     |            |    \ /    |                  |
     |             """""""""""  ?,?              |
     |                                           |
     |                                           |
      """"""""""""""""""""""""""""""""""""""""""" W,H

找到边界矩形的坐标是否有任何一般方程式?

谢谢....

哈里斯。


This question already has an answer here:

I have rectangle with co-ordinates(x1,y1) and (x2,y2) and I have to rotate the rectangle an amount of θ about it centre using Rotation Matrix

 |  cosθ  sinθ |
 | -sinθ  cosθ |

I need to find the co-ordinates of bounding rectangle after rotation.

Before rotation

0,0
 |"""""""""""""""""""""""""""""""""""""""""""|
 |                                           |
 |  x1,y1                                    |
 |       |"""""""""""""|                     |
 |       |             |                     |
 |       |             |                     | 
 |       |             |                     |
 |       """""""""""""" x2,y2                |
 |                                           |
 |                                           |
  """"""""""""""""""""""""""""""""""""""""""" W,H

After rotation

 0,0
     |"""""""""""""""""""""""""""""""""""""""""""|
     |           ?,?                             |
     |            |""""/\"""""|                  |      
     |            |   /   \   |                  |
     |            |  /      \ |                  |
     |            | /        /|                  |
     |            |/        / |                  |
     |            |\       /  |                  |
     |            |  \    /   |                  |
     |            |    \ /    |                  |
     |             """""""""""  ?,?              |
     |                                           |
     |                                           |
      """"""""""""""""""""""""""""""""""""""""""" W,H

Is there any general equation for finding the co-ordinates of bounding rectangle?.

Thanks....

Haris.


原文:https://stackoverflow.com/questions/19830477
更新时间:2022-03-15 08:03

最满意答案

查询表通常很慢而且很麻烦。 如果你使用其中一个httprequest对象,它会更快,你可以更好地控制如何解析响应。 下面是不管理会话或检查页面是否被缓存的基本示例。

Option Explicit

Sub test()
Dim rng As Range
Dim code As String

    Set rng = Sheet1.Range("A1")
    code = "8E4374"
    Articolo rng, code

End Sub

Sub Articolo(myRange As Range, code As String)
  Dim myURL As String
  Dim myName As String

  myURL = "http://techstore.runner.it/feed/dettagli_csv.php?codcli=111367&pwd=03142110786&sku=" & code
  myRange.Value = ExecuteWebRequest(myURL)

End Sub

Function ExecuteWebRequest(ByVal url As String) As String

    Dim oXHTTP As Object

    Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
    oXHTTP.Open "GET", url, False
    oXHTTP.send
    ExecuteWebRequest = oXHTTP.responseText
    Set oXHTTP = Nothing

End Function

编辑:上面的代码设计为作为Sub而不是UDF运行。 由于UDF不能影响其他单元格,唯一的选择是将字符串返回到调用单元格或调用设置代码以作为事件或从控件(例如按钮)运行

下面是一个示例UDF,它使用=Articolo(C1)从Excel调用,其中C1是包含所需代码的任何单元格,例如8E4374

Option Explicit

Function Articolo(ByVal code As String) As String
Dim myURL As String

  myURL = "http://techstore.runner.it/feed/dettagli_csv.php?codcli=111367&pwd=03142110786&sku=" & code
  Articolo = ExecuteWebRequest(myURL)

End Function

Function ExecuteWebRequest(ByVal url As String) As String
Dim oXHTTP As Object

    Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
    oXHTTP.Open "GET", url, False
    oXHTTP.send
    ExecuteWebRequest = oXHTTP.responseText
    Set oXHTTP = Nothing

End Function

此外,由于这是在发出http请求,每次强制完全重新计算你的UDF也会重新计算,这可能不是你想要的,因为你可能会发出数百或数千个请求。 我建议只从定义的循环中运行一次,例如

For Each code in Listofcodes : <Download Page> : Next code

Querytables are often slow and cumbersome. If you use one of the httprequest objects instead it's much quicker and you have more control over how to parse the response. Below is basic example that doesn't manage sessions or check if the page is cached.

Option Explicit

Sub test()
Dim rng As Range
Dim code As String

    Set rng = Sheet1.Range("A1")
    code = "8E4374"
    Articolo rng, code

End Sub

Sub Articolo(myRange As Range, code As String)
  Dim myURL As String
  Dim myName As String

  myURL = "http://techstore.runner.it/feed/dettagli_csv.php?codcli=111367&pwd=03142110786&sku=" & code
  myRange.Value = ExecuteWebRequest(myURL)

End Sub

Function ExecuteWebRequest(ByVal url As String) As String

    Dim oXHTTP As Object

    Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
    oXHTTP.Open "GET", url, False
    oXHTTP.send
    ExecuteWebRequest = oXHTTP.responseText
    Set oXHTTP = Nothing

End Function

EDIT: the above code is designed to run as a Sub rather than a UDF. Since a UDF cannot affect other cells the only option is to return the string to the calling cell or call set up the code to run as either an event or from a control (eg a button)

Below is an example UDF, it's called from Excel using =Articolo(C1) where C1 is any cell containing the required code eg 8E4374

Option Explicit

Function Articolo(ByVal code As String) As String
Dim myURL As String

  myURL = "http://techstore.runner.it/feed/dettagli_csv.php?codcli=111367&pwd=03142110786&sku=" & code
  Articolo = ExecuteWebRequest(myURL)

End Function

Function ExecuteWebRequest(ByVal url As String) As String
Dim oXHTTP As Object

    Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
    oXHTTP.Open "GET", url, False
    oXHTTP.send
    ExecuteWebRequest = oXHTTP.responseText
    Set oXHTTP = Nothing

End Function

Also, as this is making http requests, everytime you force a full re-calc your UDF's will also re-calc which is probably not what you want as you could be making hundreds or thousands of requests. I would suggest running it once only from a defined loop such as

For Each code in Listofcodes : <Download Page> : Next code

相关问答

更多
  • 试试这个: Private Sub Worksheet_Change(ByVal Target As Range) With Target If .Cells.Count > 1 Then Exit Sub If .Row >= 59 And .Row <= 10000 _ And .Column <= 4 Then Range(Cells(.Row, .Column + 1), Cells(.Row, 5)).Cle ...
  • excel怎么使用VBA[2022-04-29]

    excel使用VBA主要是通过宏运行的模式 一般要求来说 如果你没有VBA知识 建议用excel公式 VBA的代码在excel开发工具界面 可以在常规选项中 开发工具可见处打勾 就可以看到visual basic 和 宏两个选项 进去就能输入代码
  • 在使用字符串时,列是A,B,C ......。 如果他们是数字,你需要做的稍微不同: With mySheet .Range(.cells(1,columDelete), .cells(1,columDelete + deletedRowAmount)).EntireColumn.Delete End With Columns are A,B,C,... when used in a string as you are using them. If they are numbers you ...
  • 添加列标签(稍后可能会删除)应用此处描述的过程并过滤ColumnC以删除该列中的空白行。 Add column labels (may be deleted later) apply the process described here and filter ColumnC to delete rows blank in that column.
  • 会有这样的工作吗? Dim i as Variant Dim j as Variant For i = 4 to 32 For j = 3 to 9 If Cells(i,j).Value="" Then MsgBox "Missing value in Cell(" & i & " ," & j & ")." End If Next j Next i Would something like this work? Dim i as Variant Dim j as Va ...
  • 我只能提供部分答案,因为如果没有完整的JSON响应文本,我无法重新创建它。 JSON中的多值响应返回一个类型为Collection的Object。 因此你必须使用一个循环遍历所有的响应。 喜欢这个: Dim Json As Object Set Json = JsonConverter.ParseJson(xmlhttp.ResponseText) For Each singleJsonItem In Json 'What object type is singleJsonIte ...
  • 您是否考虑过将这些信息放在最右边的两个新列中( DE和DF )? 然后你可以隐藏Q到DD ,或删除那些列。 至于执行此操作的循环代码: Dim cr As Long 'current row Dim cc As Long 'current column For cr = 2 To 12000 For cc = 17 To 108 Step 2 If Cells(cr, cc).Value = "R" Then 'make column 109 (DE) in current row ...
  • 查询表通常很慢而且很麻烦。 如果你使用其中一个httprequest对象,它会更快,你可以更好地控制如何解析响应。 下面是不管理会话或检查页面是否被缓存的基本示例。 Option Explicit Sub test() Dim rng As Range Dim code As String Set rng = Sheet1.Range("A1") code = "8E4374" Articolo rng, code End Sub Sub Articolo(myRange A ...
  • 如果它仅用于显示目的,那么我认为有一种更简单的方法。 您可以将列宽设置为您喜欢的宽度,并将该列中的单元格格式化为Wrap Text。 您的Querytable有两个设置需要注意。 默认情况下,“调整列宽”未选中,您需要进行检查。 如果不这样做,Excel将使列更大,并且检查Wrap Text的事实无关紧要。 默认情况下会选中“保留单元格格式”,并且需要保持选中状态。 这将确保为该列保留Wrap文本。 除非使用固定字体,否则设置列宽并不能保证获得特定数量的字符。 但是,如果你只是想要接近,这应该工作。 If ...
  • 这将如下工作。 例如,您需要在工作表上的A1:A10范围内切换True / False值。 然后打开VBE窗口(Alt-F11)并转到工作表,右键单击,选择SelectionChange()的事件并编写以下代码。 这是相当自我解释的: Private Sub Worksheet_SelectionChange(ByVal Target as Range) Dim Intersection as Range Set Intersection = Application.Intersect(Ta ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)