Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

3D computer graphics: Model your world

From its start as an exotic research topic in government and university labs, virtual reality is making its move into the mainstream of corporate America -- find out how you can gain entry into this elite club

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Explore your world

As far as I know, we can't just stick a bit of our world directly inside a computer (without damaging the computer, anyway). The best we can do is to create a computer model of our world. Given that limitation, how do we model something like a chair, for example?

Objects in our world have characteristics, or properties, such as shape, size, weight, position, orientation, and color (and the list goes on and on). Let's consider for a moment only their shape, position, and orientation -- these properties are what we call spatial properties. And let's start with something easier to work with than a chair -- a cube, for example.

Take a look at the illustration in Figure 1. It shows a cube sitting in an otherwise empty room. (Well okay, the room has a door, too, but that's there only to make the room look more like a room.)

Figure 1: A room with a cube

In order to specify the shape, position, and orientation of a cube we need to specify the location of each of its corners. In order to do that, we could use language like this:

The first corner is a foot (or meter, if you prefer) above the floor and two and a half feet (or meters) from the wall behind me. The second corner is also a foot above the floor and a foot from the wall to my left.


Note that both of the corners were specified relative to something else (the wall and/or the floor). In our computer model, we could define a floor and a wall and use them as points of reference, but it turns out to be much easier to simply select one point of reference (which we'll call the origin) and use that instead. For our origin, we'll use the corner formed by the two walls and the floor. Figure 2 indicates the location of our origin.

Figure 2: The origin and the coordinate axis

Now we need to indicate where each corner is located with respect to the origin. You can specify the path from the origin to a corner of the cube in a number of ways. For simplicity, we must agree on a standard. Let's do the following:

Imagine that each of the edges formed by the intersection of a wall and a wall, or a wall and the floor, is given a name -- we'll call them the x axis, the y axis, and the z axis, as indicated in Figure 2. And let's also agree up front that we'll determine the location of a corner by following this recipe:

  • First, measure how far we have to travel from the origin in a straight line parallel to the x axis
  • Then, measure how far we have to travel from that point in a straight line parallel to the y axis
  • Finally, measure how far we have to travel from that point in a straight line parallel to the z axis


Figure 3 shows the path we would follow to get to one of the cube's corners.

Figure 3: Finding your path

As a shorthand notation, let's write all of these distances as:

  • The distance from origin parallel to the x axis
  • The distance from origin parallel to the y axis
  • The distance from origin parallel to the z axis


or (even shorter):

(distance x,distance y,distance z)


This triplet of values is called the corner's coordinates. We can specify the position in space of each corner in a similar manner. We might find, for example, that the cube is this example has corners at:

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • Previous How-To Java articles