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:
Resize a triangle by a certain scaling factor

Subject: Resize a triangle by a certain scaling factor

From: Liana

Date: 30 Mar, 2011 03:16:04

Message: 1 of 5

Hello,

I'm searching for some built-in function to resize a triangle (increase its size by a certain scaling factor) while the barycenter should remain the same. Does anybody know such function?

Thanks.

Subject: Resize a triangle by a certain scaling factor

From: Matt J

Date: 30 Mar, 2011 03:24:05

Message: 2 of 5

"Liana" wrote in message <imu79k$cer$1@fred.mathworks.com>...
> Hello,
>
> I'm searching for some built-in function to resize a triangle (increase its size by a certain scaling factor) while the barycenter should remain the same. Does anybody know such function?
========================

bsxfun(@plus, bsxfun(@minus,vertices,barycenter)*scalefactor, barycenter)

Subject: Resize a triangle by a certain scaling factor

From: Liana

Date: 30 Mar, 2011 04:02:06

Message: 3 of 5

Thank u, but how can I get new vertices' coordinates from that expression? Let's say a triangle is defined as follows:
trix = [3; 5; 7];
triy = [2; 6; 4];
barycenter = (5, 4);
scalefactor = 0.2;
Could u pliz explain urexpression using this example? Thanks.

"Matt J" wrote in message <imu7ol$jd1$1@fred.mathworks.com>...
> "Liana" wrote in message <imu79k$cer$1@fred.mathworks.com>...
> > Hello,
> >
> > I'm searching for some built-in function to resize a triangle (increase its size by a certain scaling factor) while the barycenter should remain the same. Does anybody know such function?
> ========================
>
> bsxfun(@plus, bsxfun(@minus,vertices,barycenter)*scalefactor, barycenter)

Subject: Resize a triangle by a certain scaling factor

From: Matt J

Date: 30 Mar, 2011 04:29:04

Message: 4 of 5

"Liana" wrote in message <imu9vu$otd$1@fred.mathworks.com>...
> Thank u, but how can I get new vertices' coordinates from that expression? Let's say a triangle is defined as follows:
> trix = [3; 5; 7];
> triy = [2; 6; 4];
> barycenter = (5, 4);
> scalefactor = 0.2;
> Could u pliz explain urexpression using this example? Thanks.
====================

This is what I had in mind:


vertices=[trix,triy].',
barycenter=mean(vertices,2),



newvertices=bsxfun(@plus, bsxfun(@minus,vertices,barycenter)*scalefactor, barycenter)


%Check

newbarycenter=mean(newvertices,2), %same as old

plot(vertices(1,:),vertices(2,:)); hold on
plot(newvertices(1,:),newvertices(2,:)); ; hold off

Subject: Resize a triangle by a certain scaling factor

From: Liana

Date: 30 Mar, 2011 04:46:04

Message: 5 of 5

Great!! This is exactly what I was looking for. Thanks!

"Matt J" wrote in message <imubig$jfl$1@fred.mathworks.com>...
> "Liana" wrote in message <imu9vu$otd$1@fred.mathworks.com>...
> > Thank u, but how can I get new vertices' coordinates from that expression? Let's say a triangle is defined as follows:
> > trix = [3; 5; 7];
> > triy = [2; 6; 4];
> > barycenter = (5, 4);
> > scalefactor = 0.2;
> > Could u pliz explain urexpression using this example? Thanks.
> ====================
>
> This is what I had in mind:
>
>
> vertices=[trix,triy].',
> barycenter=mean(vertices,2),
>
>
>
> newvertices=bsxfun(@plus, bsxfun(@minus,vertices,barycenter)*scalefactor, barycenter)
>
>
> %Check
>
> newbarycenter=mean(newvertices,2), %same as old
>
> plot(vertices(1,:),vertices(2,:)); hold on
> plot(newvertices(1,:),newvertices(2,:)); ; hold off

Tags for this Thread

No tags are associated with 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