Theory
Shapes को Move करना
एक shape draw करना एक बात है; इसे move, resize, और rotate करना कुछ और है, और यही graphics को dynamic बनाता है। ये operations geometric transformations हैं, और तीन fundamental हैं: translation (shift), scaling (resize), और rotation (spin)।
हर एक point (x, y) को एक simple rule से नए point (x', y') में transform करता है। यह lesson हर एक के लिए rule और एक worked example देता है, फिर homogeneous coordinates introduce करता है, एक clever trick जो तीनों को एक uniform matrix operation की तरह लिखने देता है। आपकी earlier की matrix maths exactly वह है जिस पर यह build करता है।
Theory
Translation और Scaling
Translation offsets tx और ty add करके एक point shift करता है:
x' = x + tx, y' = y + ty
Example: (2, 3) को (5, -1) से translate करने पर (2+5, 3-1) = (7, 2) मिलता है। Shape बिना size या orientation बदले move होता है।
Scaling (origin के about) scale factors sx और sy से multiply करके resize करता है:
x' = x times sx, y' = y times sy
Example: (2, 3) को (2, 2) से scale करने पर (2 times 2, 3 times 2) = (4, 6) मिलता है, origin से दुगुनी दूर। 1 से ऊपर scale factors enlarge करते हैं, नीचे shrink करते हैं। Translation add करता है; scaling multiply करता है।
Theory
Origin के About Rotation
Origin के about एक angle t से rotation point को (0, 0) के around sine और cosine इस्तेमाल करते हुए spin करता है:
x' = x times cos(t) minus y times sin(t)
y' = x times sin(t) plus y times cos(t)
Example: (2, 3) को 90 degrees से rotate कीजिए। 90 degrees पर, cos(t) = 0 और sin(t) = 1, तो:
x' = 2 times 0 minus 3 times 1 = -3
y' = 2 times 1 plus 3 times 0 = 2
तो (2, 3) (-3, 2) तक rotate होता है। Point origin के around एक quarter turn anticlockwise घूमा है। Rotation size और shape preserve करता है; यह सिर्फ़ orientation बदलता है।
At a glance
| Transformation | Rule | Effect |
|---|---|---|
| Translation | x' = x + tx, y' = y + ty | Shape shift करता है (offsets add करता है) |
| Scaling | x' = x times sx, y' = y times sy | Origin के about resize करता है (multiply करता है) |
| Rotation | x' = x cos t - y sin t, y' = x sin t + y cos t | Origin के about spin करता है (sin, cos इस्तेमाल करता है) |
Formula
Homogeneous Coordinates इन्हें Unify करते हैं
एक awkwardness है: scaling और rotation multiplications हैं (matrix multiplies), पर translation एक addition है, तो ये uniformly combine नहीं होते। Homogeneous coordinates इसे fix करते हैं: एक point (x, y) को (x, y, 1) की तरह represent कीजिए और 3 by 3 matrices इस्तेमाल कीजिए। अब translation भी एक matrix multiply बन जाता है:
Translation: rows [1 0 tx] [0 1 ty] [0 0 1]
Scaling: rows [sx 0 0] [0 sy 0] [0 0 1]
Rotation: rows [cos t, -sin t, 0] [sin t, cos t, 0] [0 0 1]
तीनों matrices बन जाने पर, आप transformations को इनके matrices multiply करके एक में combine कर सकते हैं, efficient graphics की key।
Quiz
Point (2, 3) को origin के about 90 degrees से rotate करने पर (cos 90 = 0, sin 90 = 1) कौन सा नया point मिलता है?
- (2, 3), unchanged
- (-3, 2), क्योंकि x' = 2(0) - 3(1) = -3 और y' = 2(1) + 3(0) = 2
- (3, 2), coordinates को swap करते हुए
- (5, 5), इन्हें add करते हुए
Show the answer
(-3, 2), क्योंकि x' = 2(0) - 3(1) = -3 और y' = 2(1) + 3(0) = 2
Rotation formulas cos 90 = 0 और sin 90 = 1 के साथ apply कीजिए: x' = x cos t - y sin t = 2(0) - 3(1) = -3, और y' = x sin t + y cos t = 2(1) + 3(0) = 2, (-3, 2) देते हुए। Option A wrong है: एक 90-degree rotation definitely point बदलती है। Option C, (3, 2), बस coordinates swap करता है, जो y=x के about एक reflection है, rotation नहीं (rotation यहाँ एक sign change भी introduce करता है)। Option D coordinates add करता है, rotation से unrelated। 90 degrees पर cos और sin को formulas में carefully substitute कीजिए, और (2,3) (-3,2) तक rotate होता है।
Think first
Homogeneous Coordinates Extra Dimension के लिए Worth क्यों हैं?
एक '1' add करना और 3x3 matrices इस्तेमाल करना extra work जैसा लगता है। यह इतना बड़ा win क्यों है? फिर tap कीजिए।
Show the answer
क्योंकि यह ALL transformations को, translation सहित, matrix MULTIPLICATIONS बना देता है, जिसका मतलब है आप transformations की किसी भी sequence को एक single matrix में COMBINE कर सकते हैं, एक huge efficiency और simplicity gain। Homogeneous coordinates के बिना, scaling और rotation matrix multiplies हैं पर translation एक ADDITION है, तो एक transformation 'multiply फिर add' का एक mix है, और कई (scale, फिर rotate, फिर move) combine करने का मतलब है order में अलग तरह के operations juggle करना, awkward और error-prone। Homogeneous coordinates हर transformation को same footing पर रखते हैं: एक point को (x, y, 1) लिखकर और 3x3 matrices इस्तेमाल करके, translation भी एक pure matrix multiply बन जाता है। अब magic: क्योंकि ये सब matrices हैं, आप transformations की एक पूरी sequence के matrices को पहले TOGETHER MULTIPLY कर सकते हैं, एक COMBINED 3x3 matrix produce करते हुए जो पूरी sequence को capture करता है। फिर आप वह single matrix shape के हर point पर apply करते हैं, per point एक multiply, हर transformation अलग-अलग apply करने की बजाय। हज़ारों points वाले एक shape के लिए, या एक second में कई बार redrawn scene के लिए, यह enormously faster है: आप एक matrix precompute करते हैं और इसे reuse करते हैं। यह maths को clean और uniform भी बनाता है, एक point transform करना हमेशा 'एक matrix से multiply करना' है, और combined transformations के बारे में reason करना matrix algebra बन जाता है। यही वजह है virtually सारे real graphics systems (2D और 3D) internally homogeneous coordinates इस्तेमाल करते हैं; extra coordinate कई गुना अपने आप को pay करता है। Uniform matrices आपको multiplication से transformations combine करने देते हैं, यही पूरा point है।
Summary
Key takeaways
- Geometric transformations (x, y) को (x', y') में बदलकर shapes को move, resize, और rotate करते हैं।
- Translation add करके shift करता है: x' = x + tx, y' = y + ty; (2,3) by (5,-1) (7,2) देता है।
- Scaling multiply करके origin के about resize करता है: x' = xsx, y' = ysy; (2,3) by (2,2) (4,6) देता है।
- Origin के about Rotation sin और cos इस्तेमाल करता है: x' = x cos t - y sin t, y' = x sin t + y cos t; (2,3) by 90 degrees (-3,2) देता है।
- Homogeneous coordinates (x,y) को (x,y,1) की तरह लिखते हैं और 3x3 matrices इस्तेमाल करते हैं, तो translation भी एक matrix multiply बन जाता है।
- सारी transformations matrices बन जाने पर, आप matrices को multiply करके एक sequence combine कर सकते हैं।
- Memory hook: translate add करता है, scale multiply करता है, rotate sin/cos इस्तेमाल करता है; homogeneous coordinates इन सबको matrices बनाते हैं।