math

Is this method faster than Math.random()?

半城伤御伤魂 提交于 2020-02-26 21:37:28
问题 I am a beginner and have currently started working on a game for Android which uses a particle swarm optimization algorithm. I am now trying to optimize my code a little and i have quite a lot of Math.random() in for-loops which is running almost all the time. So i was thinking of a way to get around and skip all the Math.random() calls. By using a method like this: float random[] = new float[100]; static int randomIndex=0; private float myRandom(){ if(randomIndex >= 99) randomIndex = 0; else

Drawing directions fields

半城伤御伤魂 提交于 2020-02-26 09:38:51
问题 Is there a way to draw direction fields in python? My attempt is to modify http://www.compdigitec.com/labs/files/slopefields.py giving #!/usr/bin/python import math from subprocess import CalledProcessError, call, check_call def dy_dx(x, y): try: # declare your dy/dx here: return x**2-x-2 except ZeroDivisionError: return 1000.0 # Adjust window parameters XMIN = -5.0 XMAX = 5.0 YMIN = -10.0 YMAX = 10.0 XSCL = 0.5 YSCL = 0.5 DISTANCE = 0.1 def main(): fileobj = open("data.txt", "w") for x1 in

Drawing directions fields

笑着哭i 提交于 2020-02-26 09:38:09
问题 Is there a way to draw direction fields in python? My attempt is to modify http://www.compdigitec.com/labs/files/slopefields.py giving #!/usr/bin/python import math from subprocess import CalledProcessError, call, check_call def dy_dx(x, y): try: # declare your dy/dx here: return x**2-x-2 except ZeroDivisionError: return 1000.0 # Adjust window parameters XMIN = -5.0 XMAX = 5.0 YMIN = -10.0 YMAX = 10.0 XSCL = 0.5 YSCL = 0.5 DISTANCE = 0.1 def main(): fileobj = open("data.txt", "w") for x1 in

Sorting portrait and landscape images

只愿长相守 提交于 2020-02-25 04:46:52
问题 Is it possible to sort an array of images with PHP. As example I have array with mixed landscape and portrait images. 140 width for portrait and 280 for landscapes. I want to create a function which check if position 1 is portrait and position 2 landscape, then position 3 must be portrait to prevent gaps in the gallery. 回答1: use getimagesize to check portrait or landscape PHP Code: $size = getimagesize($filename); $width = $size[0]; $height = $size[1]; $aspect = $height / $width; if ($aspect

Sorting portrait and landscape images

送分小仙女□ 提交于 2020-02-25 04:44:21
问题 Is it possible to sort an array of images with PHP. As example I have array with mixed landscape and portrait images. 140 width for portrait and 280 for landscapes. I want to create a function which check if position 1 is portrait and position 2 landscape, then position 3 must be portrait to prevent gaps in the gallery. 回答1: use getimagesize to check portrait or landscape PHP Code: $size = getimagesize($filename); $width = $size[0]; $height = $size[1]; $aspect = $height / $width; if ($aspect

Is it possible to express “t” variable from Cubic Bezier Curve equation?

南楼画角 提交于 2020-02-24 05:45:48
问题 I want draw bezier curve only by fragment shader to connect nodes in my editor. I know all 4 points that define Bezier Curve. And Fragment Shader is called for every pixel, so i can just check: if "t" for gl_Coord.x is between 0 and 1 then set frag_color to Red for example. I want to avoid loops in shader that's inefficient. Best way, i think, is check for points that lay on the curve. But how to do it for Bezier Curves? Is it possible to express "t" variable from cubic bezier equation? x = (

Logarithmic scale returns NaN

穿精又带淫゛_ 提交于 2020-02-23 09:09:09
问题 I have issues creating a logarithmic scale in d3. The scale works fine if it is set to linear. This works: var myLinScale = d3.scale.linear() .domain([0, 100]) .range([50, 1150]); console.log(myLinScale(71)); //output = 831 However, this doesn't work: var myLogScale = d3.scale.log() .domain([0, 100]) .range([50, 1150]); console.log(myLogScale(71)); //output = NaN What is wrong with the logarithmic scale? 回答1: New solution (using D3 v5.8) After more than 2 years this question finally has a D3

Progress Bar for Leveling System

蹲街弑〆低调 提交于 2020-02-23 07:39:06
问题 So this is kind of 2 questions in one, but basically I'm making a ranking/leveling system for my Discord bot (Discord.js) and I'm having problems with a progress bar for the next level. Here's what I've got so far: const x = "□"; let progressBarArr = [x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x]; let currentLevel = Math.ceil(result.allocatedExp/1000)*1000; if (currentLevel < 1000) currentLevel = 1000; let progressBar = "["+progressBarArr.fill("=", Math.ceil(result

Convert (x, y) pixel coordinates in google.maps.Point

随声附和 提交于 2020-02-22 12:25:35
问题 I am trying to find out the LatLng based on my x,y pixel coordinates (and of course map options, such as zoom and center). In order to do so, I posted another question and someone came up with this solution, from this post: /** * @param {google.maps.Map} map * @param {google.maps.Point} point * @param {int} z * @return {google.maps.LatLng} */ var pointToLatlng = function(map, point, z){ var scale = Math.pow(2, z); var normalizedPoint = new google.maps.Point(point.x / scale, point.y / scale);

Convert (x, y) pixel coordinates in google.maps.Point

◇◆丶佛笑我妖孽 提交于 2020-02-22 12:19:52
问题 I am trying to find out the LatLng based on my x,y pixel coordinates (and of course map options, such as zoom and center). In order to do so, I posted another question and someone came up with this solution, from this post: /** * @param {google.maps.Map} map * @param {google.maps.Point} point * @param {int} z * @return {google.maps.LatLng} */ var pointToLatlng = function(map, point, z){ var scale = Math.pow(2, z); var normalizedPoint = new google.maps.Point(point.x / scale, point.y / scale);