Geometry of line

एक line इसके slope से describe होती है, यह कितनी steeply rise होती है, y में change को x में change से divide करके दिया गया, पर एक screen सिर्फ़ पूरे pixels light up कर सकती है, तो एक line draw करने का मतलब है वे pixels choose करना जो उस ideal straight path को best approximate करते हैं।

10 min read · 6 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

Ideal Line Pixel Grid से मिलती है

Mathematically, एक line दो points के बीच एक perfectly straight, continuous path है। पर एक screen whole-number positions पर discrete pixels की एक grid है, और ideal line usually pixels के बीच से गुज़रती है, इनके centres से neatly नहीं।

तो एक raster screen पर एक line draw करना really एक approximation का problem है: कौन से whole pixels उस ideal straight path को best represent करते हैं? इसका answer देने वाले algorithms से पहले, आपको geometry चाहिए: एक line का slope, और pixel grid एक choice क्यों force करती है। यह lesson वह groundwork lay करता है; अगली इसे working algorithms में बदल देती है।

Theory

Slope: एक Line कितनी Steeply Rise होती है

(x1, y1) से (x2, y2) तक एक line का एक slope है, m लिखा जाता है, जो measure करता है यह कितनी steeply rise होती है:

m = (y2 - y1) / (x2 - x1) = dy / dx

जहाँ dy y में change है और dx x में change। उदाहरण के लिए, (0, 0) से (5, 3) तक एक line का slope m = 3 / 5 = 0.6 है, यह हर 1 unit across के लिए 0.6 units rise करती है। Full line equation *y = mx + c** है, जहाँ c y-intercept है (जहाँ line y-axis को cross करती है)। Slope key number है: यह आपको line की direction बताता है और, crucially, draw करते समय इसके along कैसे step करना है।

Formula

Faster-Changing Axis के Along Step कीजिए

Slope decide करता है आपको line को pixel by pixel कैसे walk करना चाहिए। अगर slope का magnitude 1 या कम है (|m| <= 1, line ज़्यादा horizontal है), आप x के along एक बार में एक pixel step करते हैं और matching y compute करते हैं। अगर magnitude 1 से ज़्यादा है (|m| > 1, ज़्यादा vertical है), आप y के along step करते हैं और x compute करते हैं।

क्यों? Faster-changing axis के along step करना ensure करता है आप हर row (या column) में कोई gaps नहीं के साथ एक pixel place करें। गलत axis के along step कीजिए और एक steep line disconnected dots की तरह आएगी। यह 'dominant axis के along step कीजिए' rule हर line-drawing algorithm के नीचे है।

Quiz

(0, 0) से (5, 3) तक draw की गई एक line का slope क्या है?

  1. 5/3, लगभग 1.67
  2. 3/5, जो 0.6 है (rise 3 over run 5)
  3. 8, coordinates का sum
  4. 1, क्योंकि सारी lines का slope 1 होता है
Show the answer

3/5, जो 0.6 है (rise 3 over run 5)

Slope m = (y2 - y1) / (x2 - x1) = (3 - 0) / (5 - 0) = 3/5 = 0.6। Line 5 units के run के over 3 units rise करती है, तो इसका slope 0.6 है। Option A ratio को invert करता है (rise over run की बजाय run over rise); slope dy/dx है, dx/dy नहीं। Option C coordinates add करता है, जिसका slope से कोई लेना-देना नहीं है। Option D false है: lines की अलग slopes होती हैं इनकी direction के आधार पर; सिर्फ़ एक 45-degree line का slope 1 होता है। Slope को y में change divided by x में change की तरह compute कीजिए; यहाँ वह 3/5 = 0.6 है, और चूँकि यह 1 या कम है, आप draw करते समय x के along step करेंगे।

Think first

एक Line Draw करना बिल्कुल एक Approximation क्यों होना चाहिए?

एक computer exact line क्यों draw नहीं कर सकता? Pixel approximation को कौन force करता है? फिर tap कीजिए।

Show the answer

क्योंकि एक raster screen fixed grid positions पर सिर्फ़ WHOLE pixels turn on कर सकती है, जबकि एक true mathematical line एक continuous path है जो almost हमेशा उन grid points के BETWEEN से गुज़रती है, तो exact line simply display नहीं की जा सकती, सिर्फ़ nearest pixels से approximate की जा सकती है। (0,0) से (5,3) तक line सोचिए। इसके true points में places शामिल हैं जैसे (1, 0.6) और (2, 1.2), y-values fractions हैं। पर 'pixel (1, 0.6)' light up करने जैसी कोई चीज़ नहीं है; pixels सिर्फ़ integer coordinates पर exist करते हैं जैसे (1,0) या (1,1)। तो computer को DECIDE करना पड़ता है, हर column के लिए, कौन सा integer-row pixel उस point पर ideal line के लिए best खड़ा होता है, यहाँ, क्या (1, 0.6) pixel (1,0) या (1,1) से better represent होता है? (1,1) choose करते हुए क्योंकि 0.6, 1 तक round होता है। हर step के लिए ऐसा करना pixels की एक staircase produce करता है जिसे हमारी आँखें एक line की तरह पढ़ती हैं, पर यह fundamentally एक discrete grid पर continuous ideal का एक approximation है, एक process जिसे rasterisation कहते हैं। यही वजह है diagonal lines भी slightly jagged दिख सकती हैं (aliasing): grid एक smooth slope को perfectly represent नहीं कर सकती। Line-drawing algorithms (DDA, Bresenham) की पूरी art यह है इस approximation को FAST और possible जितना visually faithful बनाना, efficiently best pixels choose करना। Pixel grid की discreteness root cause है: continuous geometry को whole pixels पर sample करना पड़ता है, तो drawing हमेशा closest ones choose करना है। Continuous line, discrete grid, इसलिए approximation।

Summary

Key takeaways

  • एक true line continuous है, पर एक raster screen discrete pixels की एक grid है, तो एक line draw करने का मतलब है इसे closest pixels से approximate करना (rasterisation)।
  • (x1,y1) से (x2,y2) तक एक line का slope m = (y2-y1)/(x2-x1) = dy/dx है।
  • Example: (0,0) से (5,3) का slope 3/5 = 0.6 है (rise 3 over run 5); line equation y = m*x + c है।
  • Faster-changing axis के along step कीजिए: अगर |m| <= 1 x के along step कीजिए, अगर |m| > 1 y के along step कीजिए, gaps से बचने के लिए।
  • Ideal line pixels के बीच से गुज़रती है, तो computer को हर step पर nearest whole pixel choose करना पड़ता है।
  • यह approximation ही वजह है diagonal lines jagged दिख सकती हैं, और यही वजह है line-drawing algorithms exist करते हैं।
  • Memory hook: slope rise over run है; pixel grid आपको closest pixels choose करने के लिए force करती है, dominant axis के along step करते हुए।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Line generation

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Geometry of line · Computer Graphics (Minor-6-03) · Gri-Learn