Vector calculation

Started by dunkedbiscuit, January 27, 2012, 09:59:50 PM

Previous topic - Next topic

dunkedbiscuit

Hi

I have two SimpleVectors, with which I create a direction vector. I will use this direction vector draw a line between the two SimpleVectors. I want to draw multiple lines that are parallel to this line, and with a bit of distance between them. Does anyone know how I could do this?

Many thanks

EgonOlsen


dunkedbiscuit

Not really, what would be ideal would be to align a place with the direction vector, so that both ends are touching the end points of the line, and the z coordinates of the plane's verts at each end of the line to be identical, so it would be level. Sort of like building a ramp.

EgonOlsen

I think i got what you want...but i don't get the actual problem...?

dunkedbiscuit

Basically, I have a line already (as in the direction vector), and I want to create a copy of it, but translated an arbitrary distance from the original line, making it parallel with the original line. My vector math is horrible!

EgonOlsen

And you have a direction vector? Then just create clones of your orginal line and translate them by a multiple of your direction vector.

dunkedbiscuit

OK. Do you have any source code?

EgonOlsen

Not sure what i should post here...it's just something like


Object3D copy=new Object3D(master, true);
SimpleVector trs=new SimpleVector(direction);
trs.scalarMul(<whatever>);
copy.translate(trs);

dunkedbiscuit

#8
Well, here's what I'm doing so far. I calculate a cross product vector between the two points on the line, and then I get the direction vector between the first point (this) and the cross product vector.

SimpleVector crossProduct = new SimpleVector( this.calcCross(otherNode) );
            SimpleVector directionVector = new SimpleVector(
                    crossProduct.x - this.x,
                    crossProduct.y - this.y,
                    crossProduct.z - this.z );


I then draw a line between the cross product and the first point using Java2D and Interact2D. I also draw a line between the first point (this) and the last point of the line (otherNode). I then draw the cross product point at the end of the line betwen the cross product and the first point, and the first point at the other end. Next, I multiply the directionVector by 0.5 using scalarMul and draw its position as a point.

The problem is that this new directionVector does not rest on the line between crossProduct and the first point (this). I think that the scalarMul somehow skews it and I don't know how to fix it. This is really the crux of my problem.

dunkedbiscuit

Not to worry. The positions didn't work as expected because there we some zeros in the SimpleVectors I was calculating the direction vector with. A satisfactory outcome.