Тёмный

Geometric transformations in Matlab using Homogeneous coordinates. 

Anselm Griffin
Подписаться 4,7 тыс.
Просмотров 1,9 тыс.
50% 1

This video demonstrates how to carry out geormetic transformations using homogeneous coordinates in Matlab. We show how to convert back to Euclidean coordinates.
Homogeneous Coordinates
IMPORTANT THIS IS NOT MY WORK
THE IP belongs to blogs.mathworks.com/graphics/...
" OK, that's kind of interesting, but why do computer graphics programmers like homogeneous coordinates so much? The answer is that in computer graphics we spend a lot of our time computing transformations between coordinate systems, and that becomes much simpler in homogeneous coordinates."
Source blogs.mathworks.com/graphics/...
" In mathematics, homogeneous coordinates or projective coordinates, introduced by August Ferdinand Möbius in his 1827 work Der barycentrische Calcul,[1][2][3] are a system of coordinates used in projective geometry, as Cartesian coordinates are used in Euclidean geometry. They have the advantage that the coordinates of points, including points at infinity, can be represented using finite coordinates. Formulas involving homogeneous coordinates are often simpler and more symmetric than their Cartesian counterparts. Homogeneous coordinates have a range of applications, including computer graphics and 3D computer vision, where they allow affine transformations and, in general, projective transformations to be easily represented by a matrix."
Source en.wikipedia.org/wiki/Homogen...
INTRODUCTION TO PATCH OBJECTS (see below)
uk.mathworks.com/help/matlab/...
%% Tidy up
clc
clear all
close all
delete(gca) % delete matlab graphics primitive
pts = [4 4 -1 -1 2 2 1 1 0 0 3 3; ...
1 3 3 -1 -1 1 1 0 0 2 2 1; ...
1 1 1 1 1 1 1 1 1 1 1 1];
axis equal
xlim([-4 4])
ylim([-4 4])
% Patch = Plot one or more filled polygonal regions
h1 = patch('FaceColor',[0.3010 0.7450 0.9330]);
h1.XData = pts(1,:) ./ pts(3,:);
h1.YData = pts(2,:) ./ pts(3,:);
title('Original shape')
"To transform a point in the projective plane back into Euclidean coordinates, we simply divide by the third coordinate: (x,y) = (X/W, Y/W). Immediately we see that the projective plane contains more points than the Euclidean plane, that is, points whose third coordinate is zero. These points are called ideal points, or points at infinity. There is a separate ideal point associated with each direction in the plane; for example, the points (1,0,0) and (0,1,0) are associated with the horizontal and vertical directions, respectively. Ideal points are considered just like any other point in and are given no special treatment. All the ideal points lie on a line, called the ideal line, or the line at infinity, which, once again, is treated just the same as any other line. The ideal line is represented as (0,0,1)."
Source robotics.stanford.edu/~birch/p...
Rotate
We're going to rotate that polygon around the origin by an angle of pi/5.
%%
h1.XData = pts(1,:) ./ pts(3,:)
h1.YData = pts(2,:) ./ pts(3,:)
mrot = [cos(pi/5), -sin(pi/5), 0; ...
sin(pi/5), cos(pi/5), 0; ...
0, 0, 1];
p2 = mrot*pts; % matrix multiply
x = p2(1,:) ./ p2(3,:);
y = p2(2,:) ./ p2(3,:);
% .9290 = a lot of red
% .69 = 69% green
% .125 =12.% blue
% overall colour is mustard
h2 = patch('FaceColor',[0.9290 0.6940 0.1250]);
h2.XData = x;
h2.YData = y;
title('rotate about y')
See above as to why we divide by the third row
Remember ./ is corresponding array location division
Scale in x and y
%%
% scale the polygon around the origin by creating a matrix
% with the scale factors in locations (1,1) and (2,2)
mscal = [1/2 0 0; ...
0 1/2 0; ...
0 0 1];
p2 = mscal*pts;
h2.XData = p2(1,:) ./ p2(3,:);
h2.YData = p2(2,:) ./ p2(3,:);
title('scale')
Reflection
%%
% a reflection around the Y=0 line just involves changing the
% sign of one of the diagonal elements
mrefl = [1 0 0; ...
0 -1 0; ...
0 0 1];
p2 = mrefl*pts;
%h2.XData= matlab.graphics.primitive.Patch
h2.XData = p2(1,:) ./ p2(3,:);
h2.YData = p2(2,:) ./ p2(3,:);
title('reflect about y')
Translation
%%
mxlat = [1 0 1.5; ...
0 1 -2; ...
0 0 1];
p2 = mxlat*pts;
h2.XData = p2(1,:) ./ p2(3,:);
h2.YData = p2(2,:) ./ p2(3,:);
title('translate')
Rotation and Translation
Remember the order is important i.e. they are not commutative
%%
p2 = mxlat*mrot*pts;
h2.XData = p2(1,:) ./ p2(3,:);
h2.YData = p2(2,:) ./ p2(3,:);
title('rotate and translate')

Опубликовано:

 

28 ноя 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии    
Далее
Genetic Algorithms Explained By Example
11:52
Просмотров 316 тыс.
MATLAB curve fitting for 1D, 2D and 3D
11:17
Просмотров 20 тыс.
Scientist think THIS is Alien?!
16:16
Просмотров 152 тыс.
Google Data Center 360° Tour
8:29
Просмотров 5 млн
Euler angles and the orientation matrix
22:14
Просмотров 10 тыс.