create and rotate a line up to a convex polygon vertex

2 ビュー (過去 30 日間)
dediydi
dediydi 2011 年 12 月 29 日
Hello,
how can i create and rotate a line up to a convex polygon vertex ?
line is tangent to vertex and rotate the line by the smallest angle between the line and the segment following the vertex it passes through (in clockwise order.)
step1: create a convex polygon step2: find the leftmost point of the polygon step3:create a line that is tangent to the leftmost point of the polygon. step4:rotate the line by the smallest angle between the line and the segment following the vertex it passes through (in clockwise order.)
step 1,2 and 3 ok, but i have problems with step 4.
i have already tried
*angle = atan2(norm(cross(v1,v2)),dot(v1,v2));*
that method but when i find the direction of vector it equal to 0 0 0 .
please help me.
thanks
  8 件のコメント
dediydi
dediydi 2011 年 12 月 29 日
not two edges. i use the angle to rotate (in clockwise) that vertical lines by the smaller angle. so it is enough to calculate the angle between the vertical line and the above edge. maybe a another picture necessary here :)
http://www.freeimagehosting.net/0f9f9
thanks for your interest.
dediydi
dediydi 2011 年 12 月 29 日
this is not correct. i will use this algorithm to draw the convex hull of two convex polygon.

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2011 年 12 月 29 日
So to calculate you're angle, v1 will always be a unit vector vertical:
v1 = [0 1 0];
v2 needs to be turned into a unit vector:
v2 = [dx dy 0]; %dx,dy are the differences in the vertex we care about and the next one over
v2 = v2./norm(v2); %make unit vector
Then calculate the angle
ang = atan2(norm(cross(v1,v2)),dot(v1,v2))
To rotate it you can use hgtransform:
x = [0 1 1 0];
y = [0 0 1 1];
h = fill(x,y,'c');
t = hgtransform('Parent',gca);
set(h,'Parent',t);
rot = makehgtform('zrotate',ang);
set(t,'matrix',rot)
More:
So something along the lines of:
P(1,:) = [1.5 2.0 0];
P(2,:) = [0.7 3.2 0];
P(3,:) = [0.5 4.5 0];
P(4,:) = [0.7 5.2 0];
P(5,:) = [1.7 5.3 0];
P(6,:) = [2.5 5.0 0];
P(7,:) = [3.0 4.5 0];
fill(P(:,1),P(:,2),'c');
v1 = [0 1 0];
v2 = P(4,:);
v2 = v2./norm(v2);
ang = atan2(norm(cross(v1,v2)),dot(v1,v2));
lineH = line([0 2],[0 10]);
pause(2) %demo
t = hgtransform('Parent',gca);
set(lineH,'Parent',t);
rot = makehgtform('zrotate',ang);
set(t,'matrix',rot)
  14 件のコメント
dediydi
dediydi 2011 年 12 月 30 日
as shown in the picture.
http://www.freeimagehosting.net/5a504
dediydi
dediydi 2011 年 12 月 30 日
maybe it is possible to use cart2sph and then rotate.

サインインしてコメントする。

その他の回答 (1 件)

Andrew Newell
Andrew Newell 2011 年 12 月 29 日
If a convex hull is your goal, you could use convhull.
  1 件のコメント
dediydi
dediydi 2011 年 12 月 29 日
i know this function but i dont want to use it.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeComputational Geometry についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by