@@ -98,7 +98,22 @@ void shear(int x1, int y1, int x2, int y2, int x3, int y3, int shx, int shy)
98
98
y3 = shy * x3 + y3;
99
99
100
100
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
+ }
102
117
103
118
int main ()
104
119
{
@@ -110,7 +125,8 @@ int main()
110
125
" 2. Rot about center\n "
111
126
" 3. Scaling\n "
112
127
" 4. Translation\n "
113
- " 5. Shear" << std::endl;
128
+ " 5. Shear\n "
129
+ " 6. Scale About Centroid" << std::endl;
114
130
115
131
int option, angle, sx, sy, tx, ty, shx, shy;
116
132
std::cin >> option;
@@ -144,6 +160,12 @@ int main()
144
160
std::cin >> shx >> shy;
145
161
shear (x1, y1, x2, y2, x3, y3, shx, shy);
146
162
}
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
+ }
147
169
148
170
else
149
171
exit (0 );
0 commit comments