简体   繁体   English

如何在Graphics3D中精确定位相机?

[英]How to precisely orient a Camera in Graphics3D?

For a simulation of a laser-based sensor I am designing, I want to verify how four points projected on a surface would appear from a camera. 对于我正在设计的基于激光的传感器的仿真,我想验证相机上投影的四个点如何出现。 And so I have undertaken to implement a Graphics3D visualization. 因此,我已承诺实现Graphics3D可视化。

The visualization places 4 lasers in a pyramid-like arrangement with a camera 20 centimeters two one side viewing the laser's projections. 可视化效果将4台激光器以金字塔状放置,并带有20厘米的摄像头,从两侧观察摄像机的投影。 My notebook code produces two views: one outside a room the sensor would operate within and a second view point which represents the camera which is rotated with the lasers. 我的笔记本代码产生两个视图:一个视图在传感器将要在房间外面运行,另一个视图代表用激光旋转的摄像机。 The Euler angles and x,y,z coordinates of the camera-laser ensemble can be controlled using sliders. 可以使用滑块控制相机-激光系的欧拉角和x,y,z坐标。

My problem is that in the simulation the camera is be being automatically oriented. 我的问题是,在仿真过程中,相机会自动定向。 And so the view from a real physical camera is not reproduced because Mathematica is adjusting the viewpoint. 因此,由于Mathematica正在调整视点,因此无法重现来自真实物理相机的视图。 If the camera and laser rotated together than rotations in Psi would cause the camera to rotate in lockstep with the laser and the view should be unchanged. 如果摄像机和激光器一起旋转,而不是Psi中的旋转,将导致摄像机与激光器同步旋转,并且视野应保持不变。 Likewise shifts in x and y shouldn't make the camera jiggle so. 同样,x和y的偏移也不应使相机抖动。

How can I control the camera orientation to produce a more coherent simulation? 如何控制相机方向以产生更连贯的模拟?

The notebook code is: 笔记本代码为:

 \[Delta] = N[(38*Degree)/2]; 
 PointPlaneIntersection[{{x1_, y1_, z1_}, 
      {x2_, y2_, z2_}, {x3_, y3_, z3_}}, 
     {{x4_, y4_, z4_}, {x5_, y5_, z5_}}] := 
    Module[{t = -Det[{{1, 1, 1, 1}, {x1, x2, x3, x4}, 
           {y1, y2, y3, y4}, {z1, z2, z3, z4}}]/
        Det[{{1, 1, 1, 0}, {x1, x2, x3, x5 - x4}, 
          {y1, y2, y3, y5 - y4}, {z1, z2, z3, 
           z5 - z4}}]}, Point[{x4 + t*(x5 - x4), 
       y4 + t*(y5 - y4), z4 + t*(z5 - z4)}]]; 
 UnitSpherePoint[azimuth_, polar_] := 
    {Cos[azimuth]*Sin[polar], Sin[azimuth]*Sin[polar], 
     Cos[polar]}; 
 Manipulate[rx := RotationMatrix[\[Theta], {1, 0, 0}]; 
    ry := RotationMatrix[\[Phi], {0, 1, 0}]; 
    rz := RotationMatrix[\[Psi], {0, 0, 1}]; 
    line1 = {{x, y, z}, rx . ry . rz . UnitSpherePoint[0, 
         Pi + \[Delta]] + {x, y, z}}; 
    line2 = {{x, y, z}, rx . ry . rz . UnitSpherePoint[
         Pi/2, Pi + \[Delta]] + {x, y, z}}; 
    line3 = {{x, y, z}, rx . ry . rz . UnitSpherePoint[
         Pi, Pi + \[Delta]] + {x, y, z}}; 
    line4 = {{x, y, z}, rx . ry . rz . UnitSpherePoint[
         3*(Pi/2), Pi + \[Delta]] + {x, y, z}}; 
    cline = {{x + 0.2, y, z}, 
      rx . ry . rz . UnitSpherePoint[0, Pi] + 
       {x + 0.2, y, z}}; roomplane := 
     {{0, 0, 0}, {30, 0, 0}, {0, 15, 0}}; 
    Scene := Graphics3D[{Red, Opacity[1], 
       PointPlaneIntersection[roomplane, line1], 
       PointPlaneIntersection[roomplane, line2], 
       PointPlaneIntersection[roomplane, line3], 
       PointPlaneIntersection[roomplane, line4], White, 
       Opacity[0.1], Cuboid[{0, 0, 0}, {30, 15, 6}]}, 
      Boxed -> False, Lighting -> "Neutral"]; 
    Grid[{{Show[Scene], Show[Scene, ViewVector -> cline, 
        ViewAngle -> 64*Degree, RotationAction -> 
         "Clip"]}}], {{x, 15}, 0, 30}, {{y, 7.5}, 0, 15}, 
   {{z, 3}, 0, 6}, {{\[Theta], Pi}, 0, 2*Pi}, 
   {{\[Phi], Pi}, 0, 2*Pi}, {{\[Psi], Pi}, 0, 2*Pi}]

As I guess you are fully aware, you need to somehow specify the camera position, orientation and angle of view. 据我所知,您需要以某种方式指定相机的位置,方向和视角。 In typical Mathematica fashion, you can do this by specifying a million different subsets of interrelated options. 以典型的Mathematica方式,可以通过指定一百万个相互关联的选项的不同子集来实现。 The following is how I would do it: 以下是我的处理方式:

Firstly, the camera position. 首先,摄像机的位置。 This can be specified in graphics coordinates ( ViewVector ) or relative to the bounding box ( ViewPoint ). 可以在图形坐标( ViewVector )中或相对于边界框( ViewPoint )进行指定。 Either of these should work. 这些都应该起作用。 While specifying the camera position, remember that the perspective effects diminish when you move further away from ViewCenter . 在指定相机位置时,请记住,当您远离ViewCenter时,透视效果会减弱。

The camera orientation is defined by the ViewCenter (specifying 2 degrees of the camera orientation) and ViewVertical (the direction that will end up being vertical in the 2D projection). 摄像机的方向由ViewCenter (指定摄像机方向的2度)和ViewVertical (最终在2D投影中ViewVertical垂直的方向)定义。 ViewCenter is usually fine by default if you have specified a PlotRange . ViewCenter如果指定一个是通常默认罚款PlotRange

Finally, Automatic is most often fine for ViewAngle if you have a well defined PlotRange , but you might need to set SphericalRegion to true if you are moving around your subject. 最后,如果您有一个定义良好的PlotRange ,则对ViewAngleAutomatic通常最ViewAngle ,但是如果您正在移动主题,则可能需要将SphericalRegion设置为true。

All the view geometry options are listed here , but I guess ViewRange is about the only one I haven't mentioned above :). 这里列出所有视图几何选项,但是我想ViewRange是我上面没有提到的唯一一个:)。 As far as I can tell, you just need to specify ViewVertical ? 据我所知,您只需要指定ViewVertical

I think that all you need to do is instead of using the ViewVector option, set 我认为您需要做的就是代替使用ViewVector选项,设置

ViewPoint -> {x, y, z}

Some of the jiggling is due to the laser/plane intersection points moving too far out of the room. 某些抖动是由于激光/平面相交点移离房间太远而引起的。 It might be best to truncate these somehow. 最好以某种方式截断这些。

Aside: your code calculates rx . ry . rz 除了:您的代码计算rx . ry . rz rx . ry . rz rx . ry . rz five times, it's probably best to calculate it once and store it. rx . ry . rz五次,最好计算一次并存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM