### Author Topic: Vector calculation  (Read 2604 times)

#### dunkedbiscuit

• byte
• • Posts: 20 ##### Vector calculation
« on: January 27, 2012, 09:59:50 pm »
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

•     • • Posts: 12225 ##### Re: Vector calculation
« Reply #1 on: January 28, 2012, 12:11:48 am »
Lines just like...lines? In that case, maybe this helps: http://www.jpct.net/forum2/index.php/topic,1679.msg12555.html

#### dunkedbiscuit

• byte
• • Posts: 20 ##### Re: Vector calculation
« Reply #2 on: January 28, 2012, 12:28:43 am »
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

•     • • Posts: 12225 ##### Re: Vector calculation
« Reply #3 on: January 28, 2012, 11:59:25 am »
I think i got what you want...but i don't get the actual problem...?

#### dunkedbiscuit

• byte
• • Posts: 20 ##### Re: Vector calculation
« Reply #4 on: January 28, 2012, 03:09:39 pm »
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

•     • • Posts: 12225 ##### Re: Vector calculation
« Reply #5 on: January 28, 2012, 05:43:26 pm »
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

• byte
• • Posts: 20 ##### Re: Vector calculation
« Reply #6 on: January 28, 2012, 07:35:39 pm »
OK. Do you have any source code?

#### EgonOlsen

•     • • Posts: 12225 ##### Re: Vector calculation
« Reply #7 on: January 29, 2012, 01:18:56 pm »
Not sure what i should post here...it's just something like

Code: [Select]
`Object3D copy=new Object3D(master, true);SimpleVector trs=new SimpleVector(direction);trs.scalarMul(<whatever>);copy.translate(trs);`

#### dunkedbiscuit

• byte
• • Posts: 20 ##### Re: Vector calculation
« Reply #8 on: January 29, 2012, 05:53:39 pm »
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.

Code: [Select]
`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.
« Last Edit: January 29, 2012, 05:57:11 pm by dunkedbiscuit »

#### dunkedbiscuit

• byte
• • Posts: 20 ##### Re: Vector calculation
« Reply #9 on: January 29, 2012, 10:35:33 pm »
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.