From 6d681b1e2a2e7d598cb2e5f4f7aac093c6e6e635 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 5 Aug 2019 09:13:17 -0600 Subject: [PATCH] Further cleanups of the SVG GridOut code. --- source/grid/grid_out.cc | 66 ++++++++++++----------------------------- 1 file changed, 19 insertions(+), 47 deletions(-) diff --git a/source/grid/grid_out.cc b/source/grid/grid_out.cc index 62cdcf9ac4..ec08f50cc9 100644 --- a/source/grid/grid_out.cc +++ b/source/grid/grid_out.cc @@ -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 -- 2.39.5