Effacer les filtres
Effacer les filtres

create and rotate a line up to a convex polygon vertex

4 vues (au cours des 30 derniers jours)
dediydi
dediydi le 29 Déc 2011
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 commentaires
dediydi
dediydi le 29 Déc 2011
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 le 29 Déc 2011
this is not correct. i will use this algorithm to draw the convex hull of two convex polygon.

Connectez-vous pour commenter.

Réponse acceptée

Sean de Wolski
Sean de Wolski le 29 Déc 2011
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 commentaires
dediydi
dediydi le 30 Déc 2011
as shown in the picture.
http://www.freeimagehosting.net/5a504
dediydi
dediydi le 30 Déc 2011
maybe it is possible to use cart2sph and then rotate.

Connectez-vous pour commenter.

Plus de réponses (1)

Andrew Newell
Andrew Newell le 29 Déc 2011
If a convex hull is your goal, you could use convhull.
  1 commentaire
dediydi
dediydi le 29 Déc 2011
i know this function but i dont want to use it.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Computational Geometry dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by