找到旋转矩形的边界矩形[重复](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
最满意答案
查询表通常很慢而且很麻烦。 如果你使用其中一个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是包含所需代码的任何单元格,例如8E4374Option 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 8E4374Option 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 和 宏两个选项 进去就能输入代码 -
VBA Excel删除多行(VBA Excel delete multiple rows)[2022-04-10]
在使用字符串时,列是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 ... -
Excel VBA将多列转置为单列多行(Excel VBA to transpose multiple columns to single column multiple rows)[2024-03-22]
添加列标签(稍后可能会删除)应用此处描述的过程并过滤ColumnC以删除该列中的空白行。 Add column labels (may be deleted later) apply the process described here and filter ColumnC to delete rows blank in that column. -
Excel VBA循环(Excel VBA Looping)[2023-05-03]
会有这样的工作吗? 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 ...