Sign in to follow this  
Ecoste

Extending a normalized vector?(3d)

Recommended Posts

Ecoste    149
Hello, I have a normalized vector on my hands(Where the camera is facing) and I basically need to extend it further(Basically, draw a line to where I'm looking at) I'm not that good at math, could any body explain how to do it? Thanks.

Share this post


Link to post
Share on other sites
taby    1265
If you are looking at a particular object...

Get the distance (... ie. the length of the vector that stretches... ) from the camera position C to the object position O being looked at: d = length(C - O).
Multiply your normalized vector by d: V = N * d.
Draw a line segment starting at C and ending at C + V.

(or just save yourself the steps and draw a line segment starting at C and ending at O) Edited by taby

Share this post


Link to post
Share on other sites
Ecoste    149
[quote name='taby' timestamp='1341172220' post='4954626']
If you are looking at a particular object...

Get the distance (... ie. the length of the vector that stretches... ) from the camera position C to the object position O being looked at: d = length(C - O).
Multiply your normalized vector by d: V = N * d.
Draw a line segment starting at C and ending at C + V.

(or just save yourself the steps and draw a line segment starting at C and ending at O)
[/quote]

Well, I basically know where I'm looking at, I just need to extend that vector and draw a line at the end of the extended version.

Share this post


Link to post
Share on other sites
taby    1265
Um ok. So it sounds like maybe you want the line segment broken up into two segments?

If not, then go with what I said earlier...

d = length(C - O)
Line segment: C to C + N*d.

If so, try...

d = length(C - O)
Unit length line segment: C to C + N
Remainder line segment: C + N to C + N + N*(d - 1).

Consider that the first method (ie. one segment) works a bit better than this second method (ie. two segments) in cases where d is less than 1.

If you're also having trouble getting lengths, multiplying, adding, then say so. Not sure. The whole point of what I tried to show is that if you want the unit vector N to instead be d units in length, then you simply multiply each of N's three components by d. If d = 0.25, you'll end up with a vector of length 0.25. If d = 34, you'll end up with a vector of length 34. Consider the opposite, where a vector becomes normalized: You get the vector's length, and then you divide each of the vector's components by that length, which leaves you with a vector of length 1. Edited by taby

Share this post


Link to post
Share on other sites
Ecoste    149
[quote name='taby' timestamp='1341175011' post='4954645']
Um ok. So it sounds like you want the line segment broken up into two segments? If not, go with what I said earlier.

If so...

d = length(C - O)

Line segment 1: C to C + N
Line segment 2: C + N to C + N + N*(d - 1).
[/quote]

But, I don't know the distance. Here's a diagram of what I want to do, it's in 2d though.(Didn't know how to do it in 3d :?) http://i.minus.com/ibkPqtmdtLP4LE.jpg

Lets go over of what I have to work with:
Everything about the camera, it's position in the 3d world, and where it's facing.

I tried multiplying everything by a value, it kind of works, but it goes too far sometime, like this, see the video.
[url="http://www.youtube.com/watch?v=X0A-CPaEuuc&feature=youtu.be"]http://www.youtube.com/watch?v=X0A-CPaEuuc&feature=youtu.be[/url]


The code I use right now is-
vector3 = x:cameraGetFacingX * (10000 * 0.1), y:cameraGetFacingY * (10000 * 0.1), z:cameraGetFacingZ * (10000 * 0.1);

drawLine(start, end);
drawLine(fromAllCharacters, vector3);

Share this post


Link to post
Share on other sites
taby    1265
Ok, again, where C is the camera position, and N is the unit look-at vector...

It's the same thing in 3D. If you want your vector to be 2 or 3 times longer, then multiply all of the vector's components by 2 or 3.

To draw your unit length red line:
Start at C and end at C + N.

To draw a longer line that includes the blue:
Start at C and end at C + N*3.

As for determining 2 or 3, or whatever the factor is... that's application dependent, and it's really your call. Best of luck.

I notice that the function call drawLine(fromAllCharacters, vector3); basically treats vector3 as a position, when it's a displacement (ie. a direction times a length). Not sure what you're trying to achieve here, since it isn't at all like what I tried to show you in the first two examples. Note how I end the line segment at C + N*d (ie. a position plus a displacement is a position), not at N*d (ie. a displacement plus nothing is a displacement). These line segment drawing functions deal in positions, not displacements.

A vector V = <V.x, V.y, V.z>, or displacement, is essentially a 1D line segment (or arrow, if you prefer) that always starts at the origin's position O = <0, 0, 0> and extends to the position <O.x + V.x, O.y + V.y, O.z + V.z>. The vector is an extended object.

A position P = <P.x, P.y, P.z> is essentially a 0D point that "starts and ends" at <P.x, P.y, P.z>. The position is not an extended object.

Both objects are defined using three components, and you can even make these components equal in value by setting P = V, but in the end they are not the same kind of object. A displacement is an extended object, a position is not. The start and end points of a line segment are not extended objects. Edited by taby

Share this post


Link to post
Share on other sites
Ecoste    149
[quote name='taby' timestamp='1341177238' post='4954654']
Ok, again, where C is the camera position, and N is the unit look-at vector...

It's the same thing in 3D. If you want your vector to be 2 or 3 times longer, then multiply all of the vector's components by 2 or 3.

To draw your unit length red line:
Start at C and end at C + N.

To draw a longer line that includes the blue:
Start at C and end at C + N*3.

As for determining 2 or 3, or whatever the factor is... that's application dependent, and it's really your call. Best of luck.

I notice that the function call drawLine(fromAllCharacters, vector3); basically treats vector3 as a position, when it's a displacement (ie. a direction times a length). Not sure what you're trying to achieve here, since it isn't at all like what I tried to show you in the first two examples. Note how I end the line segment at C + N*d (ie. a position plus a displacement is a position), not at N*d (ie. a displacement plus nothing is a displacement). These line segment drawing functions deal in positions, not displacements.

A vector V = <V.x, V.y, V.z>, or displacement, is essentially a 1D line segment (or arrow, if you prefer) that always starts at the origin's position O = <0, 0, 0> and extends to the position <O.x + V.x, O.y + V.y, O.z + V.z>. The vector is an extended object.

A position P = <P.x, P.y, P.z> is essentially a 0D point that "starts and ends" at <P.x, P.y, P.z>. The position is not an extended object.

Both objects are defined using three components, and you can even make these components equal in value by setting P = V, but in the end they are not the same kind of object. A displacement is an extended object, a position is not. The start and end points of a line segment are not extended objects.
[/quote]

Thanks a lot, it worked. Sorry for not understanding you earlier :/

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this