From: Wolfgang Bangerth Date: Mon, 5 Aug 2019 15:13:17 +0000 (-0600) Subject: Further cleanups of the SVG GridOut code. X-Git-Tag: v9.2.0-rc1~1315^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8456%2Fhead;p=dealii.git Further cleanups of the SVG GridOut code. --- 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