필터 지우기
필터 지우기

create and rotate a line up to a convex polygon vertex

조회 수: 4 (최근 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 CenterFile Exchange에서 Computational Geometry에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by