JavaSript Math sin cos tan
AD MOB
var 1_radian_to_degree = 180 / Math.PI; // 57,295779513082320876798154814105 degree
var 1_degree_to_radian = Math.PI / 180; // 0,01745329251994329576923690768489 radian
var 360_degree = 2 * Math.PI * 1_radian_to_degree;
var degree = 36.86;
var opposite = 600;
var hypotenuse = 1000;
var adjacent = 800;
// degree
// sin 45° == 0.7071067811865475;
var sin = Math.sin(45 * Math.PI / 180.0)
//sin == 0.7071067811865475;
// vypocet prepony (hypotenuse), kdyz zname
// protilehlou (opposite) a uhel (degree)
hypotenuse2 = opposite/ Math.sin(degree * Math.PI / 180.0);
// vypocet protilehle (opposite)
opposite2 = hypotenuse * Math.sin(degree * Math.PI / 180);
// vypocitat uhel alfa z velikosti protilehle a prepony ve stupnich (degree)
degree2 = Math.asin(opposite / hypotenuse)* (180/Math.PI); // 1rad
// velikost prepony pomoci prilehle (adjacent) strany a cos a uhlu v stupnich (degree)
hypotenuse3 = adjacent / Math.cos(degree * Math.PI / 180);
// velikost prilehle (adjacent) strany pomoci prepony a cos a uhlu v stupnich (degree)
adjacent2 = hypotenuse * Math.cos(degree * Math.PI / 180);
tan = Math.tan(degree * Math.PI/180); // 45° == 0.9999999999999
degree3 = Math.atan(opposite / adjacent)* (180/Math.PI); // 1rad
adjacent3 = opposite / Math.tan(degree * Math.PI / 180);
opposite3 = adjacent * Math.tan(degree * Math.PI / 180);
77LW NO topic_id
AD
Další témata ....(Topics)
How to sort array in javascript.
sort diacritical diakritika
function sortCZ(a, b) {
var token = {'á': 'a', 'č': 'c', 'ď': 'd', 'é': 'e', 'ě': 'e', 'í': 'i', 'ň': 'n', 'ř': 'r', 'š': 's', 'ť': 't', 'ú': 'u', 'ů': 'u', 'ý': 'y', 'ž': 'z'};
var code_a = (token[a]) ? token[a].charCodeAt(0) + 0.5 : a.charCodeAt(0);
var code_b = (token[b]) ? token[b].charCodeAt(0) + 0.5 : b.charCodeAt(0);
// example s=115 š will 115.5 in array immediately after s OK :)
if(token[a]){
some = token[a].charCodeAt(0) + 0.5; // 115.5
some = token[a].charCodeAt(0); // 115
}
return code_a - code_b;
}
var ar = new Array("x","č","a","c","h","z","a","ř","e","ž","ě","ň","í","d","š");
ar.sort(sortCZ);
Udaje o prohlížeči
alert(navigator.appName); // Netscape
alert(navigator.appVersion); // 5.0(Windows; en-US)
alert(navigator.appCodeName); // Mozilla
alert(navigator.appMinorVersion); // subverze prohlížeče
alert(navigator.browserLanguage);
alert(navigator.cookieEnabled); // true - false
alert(navigator.cpuClass);
alert(navigator.onLine); // true když je připojen k síti
alert(navigator.platform);
alert(navigator.systemLanguage);
alert(navigator.userAgent);
alert(navigator.userLanguage);
// zjisteni detekce prohlizece Google Chrome
var bool_is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
Pokud chceme vytvořit soubor, jehož obsah bude čten, jako UTF-8 UNICODE stačí vstupní string nechat projít funkcí utf8_encode.
Pokud pak například text souboru použijeme v php scriptu v kódování UTF-8, text souboru bude správně zobrazen.
$fHnd = fopen($newName, "w");
$row = utf8_encode('řčšě');
fwrite($fHnd, $row."\r\ n");
fclose($fHnd);
Funkce JavaScript pro práci s datumem a časem.
function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}
// console.log(msToTime(300000))
// output: 00:05:00.0
// get time difference between two dates in seconds
var startDate = new Date();
// Do your operations
var endDate = new Date();
var seconds = (endDate.getTime() - startDate.getTime()) / 1000;
var milliseconds = (endDate.getTime() - startDate.getTime());
[, OPTIONAL second param [, OPTIONAL ... param]]
static Date.now() // returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
parse(dateVal) // Date.parse('05 Dec 1998 00:12:00 GMT'); // return 912816720000
toDateString() // sunday 19.7.2020
toTimeString() // 20:15:37
getDate() // 1-31
getDay() // 0-6, 0 == Sunday
var now = new Date();
var dayOfWeekSundayIs7 = now.getDay() == 0)?7:now.getDay();
getFullYear() // 2020
getHours() // 0-23
getMilliseconds() // eg. 956
getMinutes() // 0-59
getMonth() // 0 january
getSeconds() // 0-59
getTime() // https://en.wikipedia.org/wiki/Unix_time
getTimezoneOffset() //returns the time zone difference, in minutes, from current locale
getYear() //does not return full years ("year 2000 problem"), it is no longer used and has been replaced by the getFullYear() method.
setDate(numDate) // 1-31 day of month
setHours(numHours[, numMin[, numSec[, numMilli]]]) // now.setHours(20, 21, 22); 20:21:22
setMilliseconds(numMilli) // 0-999
setMinutes(numMinutes[, numSeconds[, numMilli]]) // 0-59, 0-59, 0-999
setMonth(numMonth[, dateVal]) // 0-11
setSeconds(numSeconds[, numMilli]) 0-59 [, 0-999]
setYear(numYear) // not set full years ("year 2000 problem"), it is no longer used and has been replaced by the setFullYear() method.
setUTCDate() //
setUTCFullYear(2020) // 2020 sets the full year for a specified date according to universal time GMT
setUTCHours()
setUTCMilliseconds()
setUTCMinutes()
setUTCMonth()
setUTCSeconds()
toLocaleTimeString()
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
now.toLocaleDateString(undefined, options); //neděle 19. července 2020
// PDT Pacific Daylight Time (UTC -7)
// GMT ... SET GMT TIME +- ZONE ... new Date('December 31, 1974 23:59:30 GMT-3:00');
toGMTString() // DEPRECATED!!!! use toUTCString()
// Using UTC instead GMT!!!
var d = new Date("2020-07-15T00:00:00.000+07:00"); // UTC + 7
console.log(d.toISOString()); // "2020-07-14T17:00:00.000Z"
console.log(d.valueOf()); // 1594746000000
toISOString() // "2020-07-14T17:00:00.000Z"
toJSON() // "2020-07-14T17:00:00.000Z"
toSource() //This feature is obsolete!!!! Dont use!!!!
toString() // "Tue Jul 14 2020 19:00:00 GMT+0200 (Středoevropský letní čas)"
toUTCString() // "Tue, 14 Jul 2020 17:00:00 GMT"
valueOf() // 1594746000000
htaccess rady a zkušenosti
Testování kódu htaccess ZDEPříklady na jakpsatweb
Dokumentace na apache.org
Testování regexů
Komentar nesmi byt na stejnem radku, jako kod. Zde jsou komentare, na konci radku (vedle) prikazu, jen kvuli snadnejsimu pochopeni kodu.
RewriteCond string (regex1) # tento radek nebude fungovat, koment musi byt na samostatnem radku, nejlepe nad provadenym kodem.
# tak je to spravne, komentar na samostatnem radku a nejlepe nad ukolem
RewriteCond string (regex1)
RewriteRule dosáhne jen na regex předchozího RewriteCond!
RewriteCond string (regex1) # nedosahne
RewriteCond string (regex2)
RewriteRule (regex) %1 # v %1 bude regex2
Číslo za % udává, kolikátá skupina předchozího regexu v RewriteCond bude použita. %0 vezme vše ze všech skupin.
Pokud skupina neexistuje, tak se vypíše jako %N , kde N je číslo skupiny, která nebyla nalezena.
$1 číslo za $ udává kolikátá skupina regexu bude použita, ale platí jen pro RewriteRule z jeho vlastního regexu. $0 vezme všchny skupiny (group) regexu z RewriteRule.
RewriteCond může být několikrát za sebou, ale jakmile se jedna z těchto podmínek nesplní, tak se nesplní ani následující RewriteRule!
RewriteCond # podmínka nesplněna
RewriteCond # splněna
RewriteRule # se nevykoná, protože jedna z podmínek nebyla splněna
RewriteRule přísluší vždy k předchozímu - předchozí skupině RewriteCond. Následující RewriteRule už je samostatné viz příklad:
RewriteCond
RewriteRule # tohle reaguje na předchozí podmínku a vykoná se, když je podmínka splněna
RewriteRule # tohle už je samostatné a nebude brát ohled na podmínku - podmínky v předchozích řádcích.
Využití regexu, který bude vytvořen až v následujícím RewriteRule. Regex Back-Reference Availability
Date: 27.02.2020 - 11:11
Editace: 13.6.2020 - 13:25
Počet článků v kategorii: 77
Url:javasript-math-sin-cos-tan
AD