AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Compute screen proportion
Thema durchsuchen
Ansicht
Themen-Optionen

Compute screen proportion

Ein Thema von WojTec · begonnen am 21. Jul 2012 · letzter Beitrag vom 24. Jul 2012
Antwort Antwort
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#1

AW: Compute screen proportion

  Alt 21. Jul 2012, 14:29
It does not work because it does not make any sense.

The ratio X:Y means nothing but the fraction X/Y (“X divided by Y”). You get the ratio by doing this division.

If we do this on a computer, however, the result is naturally going to be a decimal number, e.g. 1.3333[…] for 400:300. Of course we are not happy with this, because what we wanted was a proper fraction.

So we have to go back to fraction arithmetic and do it by hand: How would we tackle 400/300 if we were in 6th grade and not allowed to use decimals? Well, of course we would cancel the fraction. The way we do this is, we find the greatest common divisor, and then divide both sides of the fraction by it. In the case of 400/300, the greatest common divisor is 100, so we end up with our result of 4:3.

Now you only have to translate this into code and you’re done. The only somewhat hard part is to find the greatest common divisor, but luckily you’ll find plenty of algorithms along with their implementations for that on the web.

Geändert von Namenloser (21. Jul 2012 um 14:33 Uhr)
  Mit Zitat antworten Zitat
freeway

Registriert seit: 11. Jul 2009
57 Beiträge
 
Delphi XE Professional
 
#2

AW: Compute screen proportion

  Alt 21. Jul 2012, 16:59
not sure, if this method works for each ratio

16:9

9 / 16 = 0,5625
1 - 0,5625 = 0,4375
1 / 0,4375 = 2,2857
16 - 9 = 7
7 * 2,2857 = 15,9999 ~ 16
16 * 0,5625 = 9


5:3

3 / 5 = 0,6
1 - 0,6 = 0,4
1 / 0,4 = 2,5
5 - 3 = 2
2 * 2,5 = 5
5 * 0,6 = 3

Geändert von freeway (21. Jul 2012 um 17:03 Uhr)
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#3

AW: Compute screen proportion

  Alt 21. Jul 2012, 17:24
Well, take a look at what happens when you fill in your intermediate terms instead of using their results:

(16 - 9) * 1 / (1 - (9 / 16)) = 15,9999 ~ 16
16 * (9 / 16) = 9

So at least the second part will always work, but it’s also completely pointless since you need to know the ratio in advance for it to give the correct result

You really shouldn’t just randomly throw together expressions not knowing what you’re doing...
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:10 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz