Borrar filtros
Borrar filtros

Draw a triangle in image knowing its center of gravity

2 visualizaciones (últimos 30 días)
jan
jan el 17 de Abr. de 2015
Comentada: Image Analyst el 17 de Abr. de 2015
i need to draw a white triangle in a black image. So the first idea that i had got is to define the three peaks that define the triangle and then recuperate the points that belong to its surface. and then affect the value 1 to these points in a black image. To recuperate the points belong to the surface of the triangle i write this code which reflects the idea that a point belongs to a plan it verifies an equation system like after: ( the plane will be the triangle)
if true
k=1;
for i=1:size_image_x
for j=1:size_image_y
equation_x=i-x_peak1==xk*(x_peak2-x_peak1)+yk*(x_peak3-x_peak1);
equation_y=j-y_peak1==xk*(y_peak2-y_peak1)+yk*(y_peak3-y_peak1);
eqx=solve(equation_x,xk,yk);
eqy=solve(equation_y,xk,yk);
if isempty(eqx)~=1 && isempty(eqy)~=1
point_x(1,k)=i;
point_y(1,k)=j;
k=k+1;
end
end
end
end
but it doesn't work
may any one help me please
thanks

Respuesta aceptada

Image Analyst
Image Analyst el 17 de Abr. de 2015
Way too complicated. Simply use poly2mask() and do it all in one line of code:
mask = poly2mask([x_peak1, x_peak2, x_peak3], [y_peak1, y_peak2, y_peak3], size_image_y, size_image_x);
  2 comentarios
jan
jan el 17 de Abr. de 2015
okay thanks a lot it is a very good and simple solution you are right. do you have any other solution if we don't have the three peaks of the triangle but we have its center of gravity????
Image Analyst
Image Analyst el 17 de Abr. de 2015
You need something else, like the radius and angle to one of the vertices or something. Obviously you could just spin a triangle around the center of gravity and they would all be triangles, just at different orientations. It's just a matter of simple trigonometry to get the three vertices once you have enough other information. What orientation do you want to draw it at? Surely you must have SOME idea.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by