Skip to content

Shifting an Object With a Geometry and Coordinate System

jth41 edited this page Dec 12, 2015 · 1 revision

In this example, we will explain how to shift a higher level object that has Geometry and a Coordinate System. We will be using the same example and class structure as in the example on making an object with a geometry and a coordinate system. It is also important to note that IShiftable and IShiftableCollection are two interfaces in this Library that are already implemented and are designed to be used in this manner and you can see those interfaces as examples if desired. We also realize that this is not the only way to shift objects, but one we designed for in this library as it is relatively straight forward, allows coordinate systems to be abstracted to the interfaces and prevents cumulative errors from doing multiple shiftToCoordinateSystems on an object. Types of Shifts There are two main types of Shifting that can be done in our example and implemented in this library, shifting an object and shifting the coordinate system that the object is displayed in. The first of these actually changes the object's location relative to the world coordinate system. The second only changes where it is displayed and not where it is located relative to the world coordinate system. The first shift will need to modify the home coordinate system and potentially the geometry, but the system shift will need to change the current coordinate system and potentially the geometry. Because of this, all of the coordinate system part of the shifting to the IShiftable Interfaces by using extension methods on the interfaces, which then delegate to an implemented abstract method inside the class that then know how to shift the geometry (only if needed - i.e. the IShiftableCollection). The first shifting, which we will just call shift, is what you use when you want to move the object around in space. If you wanted to move it two inches to the right, you would just create a new shift with a displacement of two inches. This means that you can shift the lego block object relative to the world or the lego block's system using the shift method (this method defaults to assuming the shift is in the current coordinate system, but a different one can be passed into it if desired). This works for shifting the object because we have lego block set up so that it is positioned using coordinate systems which can be shifted in any other coordinate system with this function. More on this shift for either a simple object or a compound object can be found below. The second type of shifting, which we will call shiftToCoordinateSystem, is what you would use when you just want to change the perspective you are viewing the object in. The individual objects will not move relative to the worlds, but it will change where the geometries are returned so that they are oriented about the coordinate system shifted to. This would be useful if you had multiple lego sets in the world. You could then shift the lego sets to be in the system of a particular set so that it would be front and center and aligned with the axis. This would be most useful if you needed to edit the lego blocks in that specific set but can be used for many purposes. More on this shift for either a simple object or a compound object can be found below. Shifting Lego Blocks and Lego Sets Since in our example the geometry always stays at the origin, Shifting can be done by simply changing the coordinate systems. This makes working with these simple and is convenient because it means the shifting is independent of what the geometry is and had been extracted to the IShiftable interface. This works because, in this example, we shift a copy of the geometry by a combination of its home and current coordinate systems and do not ever change the original geometry's location. This also works if the geometry can change (can be sliced for example) if the change is done correctly to the stored in the object's geometry. This means that an interface only for these simple of objects does not even need any implementation in the classes (except for declaring the two coordinate system properties). This interfac still need the distinction between shift and shiftToCoordinateSystem because the former changes the home system and the later the current system. For a lego set, the shifting is a bit more complicated. You need to do the same kind of shifting as for the basic objects, but this time you must also shift all the lego blocks in this set and any other collections in this class with the same type of shift. This means that the interface for collection objects, IShiftableCollection, must have two abstract methods for shifting the geometries in it (in addition the things in the shift interface for lego blocks): one for shifting and one for coordinate system shifting. It is important to keep these two methods separate because they will presumably be acting on objects like lego blocks, where shifting the object and shifting the coordinate systems needs to be implemented differently. Once again, it is important to note that shifting objects, like lego blocks and lego sets, do not shift the stored geometry in the object in this example.