<< Chapter < Page | Chapter >> Page > |
Recall that a point simply represents a location in space and has no width, height, or depth. Therefore a point is not visible to the human eye.However, it is sometimes useful to draw a small circle around a point to mark its location for human consumption. That is the purpose of the draw method of the GM01.Point3D class, which is shown in its entirety in Listing 4 .
Listing 4 . The method named GM01.Point3D.draw. |
---|
public void draw(Graphics2D g2D){//Get 2D projection coordinate values.
ColMatrix2D temp = convert3Dto2D(point);drawOval(g2D,temp.getData(0)-3,
temp.getData(1)+3,6,
6);}//end draw |
Purpose of the method
This method draws a small circle around the location of a point in 3D space. The 3D location of the circle is projected onto the 2D plane of the specifiedgraphics context for display later on a 2D screen. The code in Listing 4 projects that location in 3D space onto the 2D plane by calling the staticmethod named convert3Dto2D .
Behavior of the GM01.Point3D.draw method
The location of a point in 3D space, as represented by an object of the GM01.Point3D class, is actually stored in an object of the GM01.ColMatrix3D class. A reference to that ColMatrix3D object is stored in the instance variable named point belonging to the Point3D object. This reference is passed as a parameter to the convert3Dto2D method in Listing 4 .
Recall from Listing 1 that the convert3Dto2D method receives an incoming reference to an object of the class GM01.ColMatrix3D and returns a reference to an object of the class GM01.ColMatrix2D , which contains the horizontal and vertical components of the projection of the 3D point onto a2D plane.
Using the returned GM01.ColMatrix2D object
Listing 4 uses the horizontal and vertical components stored in the returned ColMatrix2D object to construct the proper parameters and call the wrapper method named GM01.drawOval . This wrapper method doesn't know that it is receiving parameters that were originally derived from an objectin 3D space. The world of the wrapper method is confined to 2D space. The wrapper method named GM01.drawOval performs the following actions:
The small circle is not converted to an ellipse
Note that even though the location of the point in 3D space is projected onto the 2D plane, the shape of the small circle is not converted to an ellipse toreflect the 3D to 2D conversion nature of the operation. Thus, if the circle were large, it wouldn't necessarily look right. However, in thiscase, the only purpose of the circle is to mark the location of a point in 3D space. Therefore, I didn't consider the actual shape of the marker to betoo important. Figure 1 shows examples of circles marking points in 3D space at the corners of the box and at the ends of the axes.
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?