]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Further cleanups of the SVG GridOut code. 8456/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 5 Aug 2019 15:13:17 +0000 (09:13 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 6 Aug 2019 15:43:37 +0000 (09:43 -0600)
source/grid/grid_out.cc

index 62cdcf9ac4bb83ce35188e5cbfc20e77ed15518c..ec08f50cc9c604a8a1f0a0193cbd008792bb9f19 100644 (file)
@@ -1529,54 +1529,26 @@ namespace
    *
    * For SVG output of grids.
    */
-  Point<2> svg_project_point(Point<3>     point,
-                             Point<3>     camera_position,
-                             Tensor<1, 3> camera_direction,
-                             Tensor<1, 3> camera_horizontal,
-                             float        camera_focus)
+  Point<2>
+  svg_project_point(const Point<3> &    point,
+                    const Point<3> &    camera_position,
+                    const Tensor<1, 3> &camera_direction,
+                    const Tensor<1, 3> &camera_horizontal,
+                    const float         camera_focus)
   {
-    // ...
-    Point<3> camera_vertical;
-    camera_vertical[0] = camera_horizontal[1] * camera_direction[2] -
-                         camera_horizontal[2] * camera_direction[1];
-    camera_vertical[1] = camera_horizontal[2] * camera_direction[0] -
-                         camera_horizontal[0] * camera_direction[2];
-    camera_vertical[2] = camera_horizontal[0] * camera_direction[1] -
-                         camera_horizontal[1] * camera_direction[0];
-
-    float phi;
-    phi = camera_focus;
-    phi /= (point[0] - camera_position[0]) * camera_direction[0] +
-           (point[1] - camera_position[1]) * camera_direction[1] +
-           (point[2] - camera_position[2]) * camera_direction[2];
-
-    Point<3> projection;
-    projection[0] = camera_position[0] + phi * (point[0] - camera_position[0]);
-    projection[1] = camera_position[1] + phi * (point[1] - camera_position[1]);
-    projection[2] = camera_position[2] + phi * (point[2] - camera_position[2]);
-
-    Point<2> projection_decomposition;
-    projection_decomposition[0] = (projection[0] - camera_position[0] -
-                                   camera_focus * camera_direction[0]) *
-                                  camera_horizontal[0];
-    projection_decomposition[0] += (projection[1] - camera_position[1] -
-                                    camera_focus * camera_direction[1]) *
-                                   camera_horizontal[1];
-    projection_decomposition[0] += (projection[2] - camera_position[2] -
-                                    camera_focus * camera_direction[2]) *
-                                   camera_horizontal[2];
-
-    projection_decomposition[1] = (projection[0] - camera_position[0] -
-                                   camera_focus * camera_direction[0]) *
-                                  camera_vertical[0];
-    projection_decomposition[1] += (projection[1] - camera_position[1] -
-                                    camera_focus * camera_direction[1]) *
-                                   camera_vertical[1];
-    projection_decomposition[1] += (projection[2] - camera_position[2] -
-                                    camera_focus * camera_direction[2]) *
-                                   camera_vertical[2];
-
-    return projection_decomposition;
+    const Tensor<1, 3> camera_vertical =
+      cross_product_3d(camera_horizontal, camera_direction);
+
+    const float phi =
+      camera_focus / ((point - camera_position) * camera_direction);
+
+    const Point<3> projection =
+      camera_position + phi * (point - camera_position);
+
+    return {(projection - camera_position - camera_focus * camera_direction) *
+              camera_horizontal,
+            (projection - camera_position - camera_focus * camera_direction) *
+              camera_vertical};
   }
 } // namespace
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.