Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
2d project of a 3d point cloud

Subject: 2d project of a 3d point cloud

From: Kira

Date: 16 May, 2008 16:10:04

Message: 1 of 7

Hi all,

I need some advice on how to get a 2D projection of a 3D
point cloud.

I have a matrix that is nx3, which I use plot3 to plot. I
can rotate the image through various angles and what I want
to do is get the 2D projection of the specific angle that I
am viewing. More specifically, I need the area of the
projection.

Any suggestions would be great. If you want to contact me
directly, please remove the words "removethis" from my email
listed above.

Thanks in advance,
Kira

Subject: 2d project of a 3d point cloud

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 16 May, 2008 17:49:52

Message: 2 of 7

In article <g0kbks$ros$1@fred.mathworks.com>,
Kira <kira.abercromby-1removethis@nasa.gov.removethis> wrote:

>I need some advice on how to get a 2D projection of a 3D
>point cloud.

>I have a matrix that is nx3, which I use plot3 to plot. I
>can rotate the image through various angles and what I want
>to do is get the 2D projection of the specific angle that I
>am viewing.

You can determine the current angles by examining the axes
Camera* properties; I would have to test to see exactly which
ones are involved (it would depend in part on whether you just
rotate or you rotate and pan.)

>More specifically, I need the area of the
>projection.

You mention that your matrix is nx3. Is that a vector of length n
in each of the three axes e.g., plot3(A(:,1),A(:,2),A(:,3))
or is that three different lines, e.g., plot3(A) or equivilently
plot3(1:n,A(:,1),ones(1,n),1:n,A(:,2),2*ones(1,n),1:n,A(:,3),3*ones(1,n))

plot3() creates lines, not surfaces and not (usually) dot plots, so
it is not immediately obvious to me what you mean by the "area" of
the projection. Is it a matter of considering the plot as occuping
a cuboid volume and finding the projection of the volume according to
the angle? That would be something that could be done by knowing the
minimum and maximum ranges along x, y, and z, together with the angles.
Or does the "area" of the projection the area of the convex hull drawn
around all of the points projected down to 2D? That would require taking
into account all of the data values.
--
  "To burn always with this hard, gem-like flame, to maintain this
  ecstasy, is success in life." -- Walter Pater

Subject: 2d project of a 3d point cloud

From: John D'Errico

Date: 16 May, 2008 20:11:02

Message: 3 of 7

"Kira " <kira.abercromby-1removethis@nasa.gov.removethis> wrote in
message <g0kbks$ros$1@fred.mathworks.com>...
> Hi all,
>
> I need some advice on how to get a 2D projection of a 3D
> point cloud.
>
> I have a matrix that is nx3, which I use plot3 to plot. I
> can rotate the image through various angles and what I want
> to do is get the 2D projection of the specific angle that I
> am viewing. More specifically, I need the area of the
> projection.
>
> Any suggestions would be great. If you want to contact me
> directly, please remove the words "removethis" from my email
> listed above.

Area is not a meaningful concept to apply to
a list of scattered data points. Perhaps you
mean the area of the convex hull?

Assuming that you have some data in an nx3
array like this...

xyz = randn(100,3); % just some random data

Use view to get the current viewing angles.

[az,el] = view;

Construct the normal vector to the viewing
plane from these angles.

az = az*pi/180;
el = el*pi/180;
normalvec=[1 0 0]*[cos(az) sin(az) 0;-sin(az) cos(az) 0;0 0 1];
normalvec=normalvec*[cos(el) 0 sin(el);0 1 0;-sin(el) 0 cos(el)];

Project into the viewing plane.

uv = xyz*null(normalvec);

Compute the convex hull in the viewing
plane.

hull = convexhull(uv(:,1),uv(:,2));

And compute the area of the resulting
polygon using polyarea.

A = polyarea(uv(hull,1),uv(hull,2));

I've not checked this very carefully. But it
should be close.

John

Subject: 2d project of a 3d point cloud

From: Kira

Date: 19 May, 2008 14:00:02

Message: 4 of 7

Hi Walter,

Thanks for the reply. My matrix is three vectors. I use
plot3 and force the dots using 'r.'.

Regarding your second point, I basically want the area
created by the "shadow" of the projection. So as I look at
the plot in 3d, I want to flatten it onto a 2D plane, find
the edge, and get the area of the piece. So, you second
thought on what I meant by area is correct.

Thanks,
Kira

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g0khg0$403$1@canopus.cc.umanitoba.ca>...
> In article <g0kbks$ros$1@fred.mathworks.com>,
> Kira <kira.abercromby-1removethis@nasa.gov.removethis> wrote:
>
> >I need some advice on how to get a 2D projection of a 3D
> >point cloud.
>
> >I have a matrix that is nx3, which I use plot3 to plot. I
> >can rotate the image through various angles and what I want
> >to do is get the 2D projection of the specific angle that I
> >am viewing.
>
> You can determine the current angles by examining the axes
> Camera* properties; I would have to test to see exactly which
> ones are involved (it would depend in part on whether you just
> rotate or you rotate and pan.)
>
> >More specifically, I need the area of the
> >projection.
>
> You mention that your matrix is nx3. Is that a vector of
length n
> in each of the three axes e.g., plot3(A(:,1),A(:,2),A(:,3))
> or is that three different lines, e.g., plot3(A) or
equivilently
>
plot3(1:n,A(:,1),ones(1,n),1:n,A(:,2),2*ones(1,n),1:n,A(:,3),3*ones(1,n))
>
> plot3() creates lines, not surfaces and not (usually) dot
plots, so
> it is not immediately obvious to me what you mean by the
"area" of
> the projection. Is it a matter of considering the plot as
occuping
> a cuboid volume and finding the projection of the volume
according to
> the angle? That would be something that could be done by
knowing the
> minimum and maximum ranges along x, y, and z, together
with the angles.
> Or does the "area" of the projection the area of the
convex hull drawn
> around all of the points projected down to 2D? That would
require taking
> into account all of the data values.
> --
> "To burn always with this hard, gem-like flame, to
maintain this
> ecstasy, is success in life." -- Walter Pater

Subject: 2d project of a 3d point cloud

From: Kira

Date: 19 May, 2008 14:02:02

Message: 5 of 7

John,

Thank you so much. I hadn't thought of using a convex hull.
 That should work. I'll let you know.

Thanks, everyone, for the help.

Kira


"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g0kpom$ib5$1@fred.mathworks.com>...
> "Kira " <kira.abercromby-1removethis@nasa.gov.removethis>
wrote in
> message <g0kbks$ros$1@fred.mathworks.com>...
> > Hi all,
> >
> > I need some advice on how to get a 2D projection of a 3D
> > point cloud.
> >
> > I have a matrix that is nx3, which I use plot3 to plot. I
> > can rotate the image through various angles and what I want
> > to do is get the 2D projection of the specific angle that I
> > am viewing. More specifically, I need the area of the
> > projection.
> >
> > Any suggestions would be great. If you want to contact me
> > directly, please remove the words "removethis" from my email
> > listed above.
>
> Area is not a meaningful concept to apply to
> a list of scattered data points. Perhaps you
> mean the area of the convex hull?
>
> Assuming that you have some data in an nx3
> array like this...
>
> xyz = randn(100,3); % just some random data
>
> Use view to get the current viewing angles.
>
> [az,el] = view;
>
> Construct the normal vector to the viewing
> plane from these angles.
>
> az = az*pi/180;
> el = el*pi/180;
> normalvec=[1 0 0]*[cos(az) sin(az) 0;-sin(az) cos(az) 0;0
0 1];
> normalvec=normalvec*[cos(el) 0 sin(el);0 1 0;-sin(el) 0
cos(el)];
>
> Project into the viewing plane.
>
> uv = xyz*null(normalvec);
>
> Compute the convex hull in the viewing
> plane.
>
> hull = convexhull(uv(:,1),uv(:,2));
>
> And compute the area of the resulting
> polygon using polyarea.
>
> A = polyarea(uv(hull,1),uv(hull,2));
>
> I've not checked this very carefully. But it
> should be close.
>
> John

Subject: 2d project of a 3d point cloud

From: Gwendolyn Fischer

Date: 20 May, 2008 06:22:02

Message: 6 of 7

Hi John,

> > Assuming that you have some data in an nx3
> > array like this...
> >
> > xyz = randn(100,3); % just some random data
> >
> > Use view to get the current viewing angles.
> >
> > [az,el] = view;
> >
> > Construct the normal vector to the viewing
> > plane from these angles.
> >
> > az = az*pi/180;
> > el = el*pi/180;
> > normalvec=[1 0 0]*[cos(az) sin(az) 0;-sin(az) cos(az)
0;0
> 0 1];
> > normalvec=normalvec*[cos(el) 0 sin(el);0 1 0;-sin(el) 0
> cos(el)];


I really like your way of solving this problem. I see that
you use the null-function quite some times to takle
different problems and even after looking at the
documentation and on different web pages the concept of
null is not quite clear to me. Why does this line work?

> >
> > Project into the viewing plane.
> >
> > uv = xyz*null(normalvec);

The rest of your algo is clear to me, but null...

> >
> > Compute the convex hull in the viewing
> > plane.
> >
> > hull = convexhull(uv(:,1),uv(:,2));
> >
> > And compute the area of the resulting
> > polygon using polyarea.
> >
> > A = polyarea(uv(hull,1),uv(hull,2));

Thank you very much for your valuable help on this
newsgroup.

Gwen

Subject: 2d project of a 3d point cloud

From: Patrik

Date: 19 Mar, 2014 10:32:07

Message: 7 of 7

I can't really get this code to work. I have a short example code, showing the errors. I create a helix in 3d and change the viewing angle. I also make a projection onto a plane as suggested above, and they should be the same, but they are not. What's wrong?

x = cos((0:50)*2*pi/50);
y = sin((0:50)*2*pi/50);
z = (0:.02:1);

e = 0;
el = e*pi/180;

for a = 0:360
    
    az = a*pi/180;
    
    normalvec=[1 0 0]*[cos(az) sin(az) 0;-sin(az) cos(az) 0;0 0 1];
    normalvec=normalvec*[cos(el) 0 sin(el);0 1 0;-sin(el) 0 cos(el)];
    pd = [x' y' z']*null(normalvec);
    
    figure(1), plot3(x,y,z);
    view(a,e);
    xlim([-2 2]); ylim([-2 2]);
    
    figure(2), plot(pd(:,1),pd(:,2),'.');
    title(['Az: ' num2str(a) ' Normal: ' num2str(n)],'interpreter','none');
    xlim([-2 2]); ylim([0 1]);
    0;
end

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <g0kpom$ib5$1@fred.mathworks.com>...
> "Kira " <kira.abercromby-1removethis@nasa.gov.removethis> wrote in
> message <g0kbks$ros$1@fred.mathworks.com>...
> > Hi all,
> >
> > I need some advice on how to get a 2D projection of a 3D
> > point cloud.
> >
> > I have a matrix that is nx3, which I use plot3 to plot. I
> > can rotate the image through various angles and what I want
> > to do is get the 2D projection of the specific angle that I
> > am viewing. More specifically, I need the area of the
> > projection.
> >
> > Any suggestions would be great. If you want to contact me
> > directly, please remove the words "removethis" from my email
> > listed above.
>
> Area is not a meaningful concept to apply to
> a list of scattered data points. Perhaps you
> mean the area of the convex hull?
>
> Assuming that you have some data in an nx3
> array like this...
>
> xyz = randn(100,3); % just some random data
>
> Use view to get the current viewing angles.
>
> [az,el] = view;
>
> Construct the normal vector to the viewing
> plane from these angles.
>
> az = az*pi/180;
> el = el*pi/180;
> normalvec=[1 0 0]*[cos(az) sin(az) 0;-sin(az) cos(az) 0;0 0 1];
> normalvec=normalvec*[cos(el) 0 sin(el);0 1 0;-sin(el) 0 cos(el)];
>
> Project into the viewing plane.
>
> uv = xyz*null(normalvec);
>
> Compute the convex hull in the viewing
> plane.
>
> hull = convexhull(uv(:,1),uv(:,2));
>
> And compute the area of the resulting
> polygon using polyarea.
>
> A = polyarea(uv(hull,1),uv(hull,2));
>
> I've not checked this very carefully. But it
> should be close.
>
> John

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us