Skip to content

Commit 47f6ebb

Browse files
authored
Update allinone.cpp
added Scale about centroid function
1 parent b68ed1c commit 47f6ebb

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

allinone.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,22 @@ void shear(int x1, int y1, int x2, int y2, int x3, int y3, int shx, int shy)
9898
y3 = shy * x3 + y3;
9999

100100
plot(x1, y1, x2, y2, x3, y3);
101-
}
101+
}
102+
103+
void ScaleAboutCentroid(int x1, int y1, int x2, int y2, int x3, int y3, int sx, int sy)
104+
{
105+
int xc = (x1 + x2 + x3) / 3;
106+
int yc = (y1 + y2 + y3) / 3;
107+
108+
x1 = x1 * sx + xc * (1 - sx);
109+
x2 = x2 * sx + xc * (1 - sx);
110+
x3 = x3 * sx + xc * (1 - sx);
111+
y1 = y1 * sy + yc * (1 - sy);
112+
y2 = y2 * sy + yc * (1 - sy);
113+
y3 = y3 * sy + yc * (1 - sy);
114+
115+
plot(x1, y1, x2, y2, x3, y3);
116+
}
102117

103118
int main()
104119
{
@@ -110,7 +125,8 @@ int main()
110125
"2. Rot about center\n"
111126
"3. Scaling\n"
112127
"4. Translation\n"
113-
"5. Shear"<< std::endl;
128+
"5. Shear\n"
129+
"6. Scale About Centroid"<< std::endl;
114130

115131
int option, angle, sx, sy, tx, ty, shx, shy;
116132
std::cin >> option;
@@ -144,6 +160,12 @@ int main()
144160
std::cin >> shx >> shy;
145161
shear(x1, y1, x2, y2, x3, y3, shx, shy);
146162
}
163+
else if(option == 6)
164+
{
165+
std::cout << "Enter scale factors(sx, sy): ";
166+
std::cin >> sx >> sy;
167+
ScaleAboutCentroid(x1, y1, x2, y2, x3, y3, sx, sy);
168+
}
147169

148170
else
149171
exit(0);

0 commit comments

Comments
 (0)