Hi Guys,

I've got a linear algebra issue I've been trying to sort out for a while. And, my problem is, I've got linear algebra resources and I've got VB6 resources (i.e., you guys), but I don't have any resources that combine the two. Therefore, you guys are drafted. Also, I bet a couple of you have done some linear algebra at some point in the past.

Basically, I'm trying to build three functions in VB6.

- Build a 3D segment.
- Rotate a 3D segment.
- Extract angles between two 3D segments.

Okay, I need to lay some groundwork. First, what's a(not to be confused with a3D segment)? Here's a little thing I carry around with me to think about this stuff:line segment

That thing represents a. If you just look at the X and Y axes, you can imagine a piece of graph paper with an origin (0,0) in the middle of the paper. The corner of my little device might be at (0,0). However, I've got to think in 3D, so I need that Z axis that sticks straight up. Therefore, the corner of all axes of the device (see picture) can be thought of as (0,0,0).3D segment

So, basically, a 3D segment is represented by four points: The origin (i.e., the corner), the X_Axis, the Y_Axis, and the Z_Axis. And, for simplicity, we will assume that each of the axes is exactlyoneunit long.

Now, let's assume we have a room with a tile floor, and we've designated an origin (0,0,0) in the middle on the floor somewhere. Let's imagine a dot there on the floor in the middle of the room. And also, we've imagined some direction as X+, and another orthogonal (perpendicular) direction as Y+. It's as if we laid a piece of graph paper on the floor of our room.

And obviously (I hope), Z+ will be straight up.

So, if we lay our little wooden 3D segment device on the room's origin (0,0,0) with its X_Axis aligned with X and its Y_Axis aligned with Y, our 3D segment would be defined as:

Origin = (0,0,0)

X_Axis = (1,0,0)

Y_Axis = (0,1,0)

Z_Axis = (0,0,1)

You still with me?

Now, we need to back up just a bit. In addition to these 3D segments, we can definepoints in spaceanywhere in our room. For convenience, we will define them as 3D vectors that originate at our origin spot in the room (just like graph paper, but 3D). Because the origin is on the floor, Z will always be positive, but X and Y can be either positive or negative (because it's most convenient to place the origin near the middle of the room).

Therefore, using this system, we can define any point in space as a 3D vector from the room's origin. We'll use a UDT to define this:

Now, let's return to our 3D segment. The 3D segment discussed above (placed at the origin) is really just four of these vectors: One at the origin, one that's one unit along the X_Axis, one that's one unit along the Y_Axis, and one that's one unit along the Z_Axis. So, to define any 3D segment, we can use another UDT:Code:Public Type VectorType x As Double y As Double z As Double End Type

Here's where thing start to get interesting. I've talked about our 3D segment being placed on (and aligned with) the origin, as such:Code:Public Type SegmentType Origin As VectorType AxisX As VectorType AxisY As VectorType AxisZ As VectorType End Type

But that doesn't necessarily have to be the case. In other words, our 3D segment can be both translated and rotated.

Translation is simply the case where our 3D segment's origin isn't positioned on the room's origin. And I'm not really concerned with translation. In the broader scheme of things, translations are easy. They're just vector addition and subtraction of origins.

Rotation is the case where a 3D segment's X_Axis (and/or Y_Axis and/or Z_Axis) is no longer aligned with (or even parallel to) the room's X_Axis (or Y_Axis or Z_Axis, respectively). Here's my attempt to take a picture of my rotated (and translated) little 3D segment device:

It's off the floor (translation), but more importantly, its axes are no longer aligned with the room. However, let's go back to ourSegmentTypeUDT. We can certainly imagine some vector (VectorType) that represents ournew3D segment's origin. Furthermore, we can imagine some vector that represents the 3D points on the ends of each of our little 3D segment's axes. They will no longer be the simple ...

Origin = (0,0,0)

X_Axis = (1,0,0)

Y_Axis = (0,1,0)

Z_Axis = (0,0,1)

... that we started with. But we could imagine measuring them in some way and figuring out all four of those points. And they would "mathematically" represent our rotated and translated 3D segment in space.

I think I'll stop this post here. I haven't gotten to the three functions I'd like,but I'm getting there.

Please feel free to make comments if you'd like. I'll be posting more soon.

Best Regards,

Elroy

.Continuing introduction/explanation of this is here