Skip to content

Shear Geometry 2

Craig McDonald requested to merge feature/shear-geometry-2 into feature/shear-geometry

Description

This merge request is for completing the work started in !404 (merged), and fixing any errors found there. The approach has been to add more comprehensive unit testing for the Geometry classes---the 3D ones in particular. I made my best effort to have the octave scripts in BurtSharp.Tests/matlab/geometry/ used for unit testing and visualization be consistent with the scripts in BurtSharp.

The changes to the GeometryBase, Geometry2D, and Geometry3D types are the result of thinking further about applying transforms to shapes. Implementing this for the 3D shapes Parallelepiped and Extrusion was the most challenging part. For the Extrusion in particular, the 3D shape is separated into two parts: a 3D Line (the main axis) that can be scaled along its length and sheared in the XZ and YZ planes, and a 2D CrossSection that can be scaled in X-Y directions and sheared in the XY plane. The shear parameters for the Line are stored in the Geometry3D base object as Beta and Gamma, and the scaling of the Line is stroed in the _lineExtent member. The shearing and scaling parameters for the CrossSection are stored in the _crossSection member, which is a Geometry2D object. When a 3D spatial transform is applied to the Extrusion, the 3D translation and rotation can be applied to the base Geometry3D object straightforwardly, and then the shear and scale must be first separated into the Line and CrossSection parts, then passed along from the base Geometry3D to the separated Line and CrossSection accordingly. Finally, the Geometry3D base object is reset to have no XY shear and no scaling, so that the parameters are only each stored/applied in one place.

The unit tests confirm the implementation of the functions DistanceToPoint(...) and IsInside(...) for the Parallelepiped and the Extrusion (for both extruded Parallelogram and extruded Ellipse), which are crucial for haptic rendering. The logic of the Parllelepiped DistanceToPoint() is very dense and complicated, but with the visuals provided by octave I am comfortable saying that it is correct without you going through it line-by-line.

Also made significant changes to the child classes of Parallelogram, Ellipse, Parallelepiped such as Square and Cube. I realized that if I allowed an arbitrary transform to be applied to a shape like Cube, then it would become a Parallelepiped, so it's not clear what the point of having that class is. I decided to add factory methods that allow you to easily construct something like a Parallelepiped with the static function Square(float edge), and then to make the actual classes like Square not implement the shearing and scaling properties that would turn them into a different shape. I don't know if these will ever be necessary, but I was sort of just following the thought to its conclusion.

Some additional highlights are:

  • having the simple closed-form solution for re-factoring an ellipse transform with shear into one with different scaling and rotation, but no shear (weird that you can do this)
  • finding the cross section of an extrusion that is perpendicular to the main axis when you have applied 3D shearing to the extrusion, for the purpose of finding the point nearest to the extrusion and its penetration depth

What to focus on

  • Problems raised in !404 (merged) have been addressed
  • The application of rotation, shear, and scaling transforms to 2D and 3D shapes has been correctly implemented

Resources

Issues

What issues does this fix?

  • Fixes #258
Edited by Craig McDonald

Merge request reports

Loading