我正在 Excel/PowerPoint 中处理 3D 形状,我需要计算特定的坐标。我使用Excel来处理操作,内容在PowerPoint中。
假设我的幻灯片上有这个形状。假设它位于 100pt X“左”和 50pt Y“上”。
模型的2D宽度为300px,高度为215pt。
我要确定的X、Y点是包含该形状的3D长方体的底面中心。
这是我的意思的粗略图表......
我可以获取形状的 .Model3D 对象和/或 .ThreeD 对象,但我无法确定计算位置所需的信息是否可用。
对于这是否可能有什么想法?
需要是我可以计算任何给定 3D 模型的东西,因为我有很多需要处理。
如果我手动执行此操作,那么我只需从锚点 (100,50) 到虚线交叉的位置画一条线,我就能够计算出新点的 X 和 Y,但我需要代码来这样做,而且我认为没有办法准确地再现 3D 模型的长方体(我的绘图只是猜测)。
感谢任何人可以提供的任何帮助。
方向是否一致?如果是这样,我们可以尝试:
Sub test()
Dim shp As Shape
Dim slide As slide
Dim topLeftX As Single, topLeftY As Single
Dim width2D As Single, height2D As Single
Dim depth As Single
Dim centerX As Single, centerY As Single
'Change to your slide and shape
Set slide = ActivePresentation.Slides(1) ' Change to your slide index
Set shp = slide.Shapes(1) ' Change to your shape index
'Extract properties
topLeftX = shp.Left
topLeftY = shp.Top
width2D = shp.Width
height2D = shp.Height
' Extract depth (3D property)
If shp.ThreeD.Visible Then
depth = shp.ThreeD.Depth
Else
depth = 0 ' Default to zero if no depth
End If
' Calculate an approximation of bottom face's center
centerX = topLeftX + (width2D / 2)
centerY = topLeftY + height2D
' Output results
Debug.Print "Center of Bottom Face: (" & centerX & ", " & centerY & ")"
' If you need this for many objects, you can use a loop, use this as a call or change it to a function
End Sub