Sign in to follow this  
Smilediver

[Solved] Vector extrusion

Recommended Posts

Hey guys. I'm a bit stuck with the following problem. I have a point C1, and two vectors going from that point: A and B (for simplicity let's say those are normals). I also have distances w1 and w2. I need to calculate point C2. Any ideas how?

[img]http://img52.imageshack.us/img52/5636/crossqt.jpg[/img]

Share this post


Link to post
Share on other sites
You just need to displace c1 by w1 in a direction perpendicular to A, then by w2 perpendicular to B.

To get a perpendicular vector, swap the components and negate one. There are two perpendiculars, and two components to negate. The combination I used below will shift the point down and right when the distances are positive.

Perpendicular vector to A = (-A.y, A.x)
to B = (B.y, -B.x)

You want to use a perpendicular direction, not a perpendicular vector here, because the length of A and B are inconsequential, its the distances who supply the magnitude of the shift. So normalize those perpendicular vectors.

direction perpendicular to A = Vector2(-A.y, A.x).normalized()
direction perpendicular to B = Vector2(B.y, -B.x).normalized()

Then multiply those unit vectors times the distances, equivalent to creating a new vector with the distance as its magnitude and the direction as its theta.

displacement 1 = w1 * Vector2(-A.y, A.x).normalized()
displacement 2 = w2 * Vector2(B.y, -B.x).normalized()

Then just apply the displacements to c1.

c2 = c1 + w1 * Vector2(-A.y, A.x).normalized() + w2 * Vector2(B.y, -B.x).normalized().

The rays emitting from c2 in the way the vectors/rays A and B emit from c1 are just c2 + A and c2 + B. (When a vector is emitting from somewhere, its being rayish.)

Share this post


Link to post
Share on other sites
[quote name='Rodimus' timestamp='1307543909' post='4820941']
Are the blue lines parallel to the red ones? Obviously looks like it in the image, but just want to make sure since you don't specify it.
[/quote]
Yes. The red vectors (that I know) are extruded by a distance of w1 and w2, and we get blue ones.

[quote name='EqualityAssignment' timestamp='1307547155' post='4820943']You just need to displace c1 by w1 in a direction perpendicular to A, then by w2 perpendicular to B.[/quote]
Unfortunately, it's not that simple, otherwise I'd solve it myself. :-) This works only if A and B are perpendicular. Note that w1 and w2 is a perpendicular distance from original red vector to extruded blue one, it's not a distance on red A and B vectors.

To give a more clear picture of what's going on, is that I have two thick lines joining at the point C1. A and B vectors are their centers, and w1 and w2 are widths (or actually half widths) of those lines. And I need to find their edge intersection point.

Share this post


Link to post
Share on other sites
If w1 and w2 are equal then there's definitely a direct way to calculate the vector (c2 - c1) -- sadly I forget the formula but it's pretty simple, I'll dig it up if you need it; otherwise I'm not sure.

The simplest solution is to offset the original lines and intersect the resulting lines to find c2.

some related links that might help:

[url="http://www.gamedev.net/topic/564443-determine-offset-points-of-polygon/page__p__4625629__hl__polygon+offset__fromsearch__1#entry4625629"]http://www.gamedev.net/topic/564443-determine-offset-points-of-polygon/page__p__4625629__hl__polygon+offset__fromsearch__1#entry4625629[/url]

[url="http://www.gamedev.net/topic/572648-outline-detection/page__p__4657548__hl__polygon+offset__fromsearch__1#entry4657548"]http://www.gamedev.net/topic/572648-outline-detection/page__p__4657548__hl__polygon+offset__fromsearch__1#entry4657548[/url]

[url="http://www.gamedev.net/topic/562159-inner-contour-of-polygon/page__p__4603637__hl__polygon+offset__fromsearch__1#entry4603637"]http://www.gamedev.net/topic/562159-inner-contour-of-polygon/page__p__4603637__hl__polygon+offset__fromsearch__1#entry4603637[/url]

Share this post


Link to post
Share on other sites
[quote name='raigan' timestamp='1307566306' post='4821072']If w1 and w2 are equal then there's definitely a direct way to calculate the vector (c2 - c1)[/quote]

Unfortunately, w1 and w2 can be different. Thanks for the links, I'll check them out.

Share this post


Link to post
Share on other sites
I actually figured out how to do it. :-) For this, I calculate wa and wb, which are projected w1 and w2 distances on A and B normalized vectors. For this, I also need AN and BN, which are extrusion directions for vectors A and B. The formulas are bellow:


A, B - normalized vectors going from C1
AN, BN - normalized vectors to the direction of A, B extrusion.

wb = w1 / (B dot AN)
wa = w2 / (A dot BN)


Also need to check if those dot products are equal to 0, to see if vectors A and B are parallel. And finally the intersection point:

C2 = A * wa + B * wb


To get wb, I needed to solve the following:

B dot AN = w1, which given dot product definition is:
wb * cos(angle between B and AN) = w1, so:
wb = w1 / cos(angle between B and AN), and knowing that:
B dot AN = |B| cos(angle between B and AN), (|B| == 1, since it's normalized) we substitute, and get:
wb = w1 / (B dot AN)


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