math

Cube to Sphere mapping (inverse function wanted)

时光怂恿深爱的人放手 提交于 2020-12-15 06:16:30
问题 I've came across a cube to sphere mapping function that provides a more uniform result than just normalizing the coordinates or other mapping methods. Unfortunately there is no unwrapping function. Source: http://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html vec3 spherify ( vec3 v ) { float x2 = v.x * v.x; float y2 = v.y * v.y; float z2 = v.z * v.z; vec3 s; s.x = v.x * sqrt(1.0 - y2 / 2.0 - z2 / 2.0 + y2 * z2 / 3.0); s.y = v.y * sqrt(1.0 - x2 / 2.0 - z2 / 2.0 + x2 * z2 / 3.0); s

Cube to Sphere mapping (inverse function wanted)

南笙酒味 提交于 2020-12-15 06:15:36
问题 I've came across a cube to sphere mapping function that provides a more uniform result than just normalizing the coordinates or other mapping methods. Unfortunately there is no unwrapping function. Source: http://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html vec3 spherify ( vec3 v ) { float x2 = v.x * v.x; float y2 = v.y * v.y; float z2 = v.z * v.z; vec3 s; s.x = v.x * sqrt(1.0 - y2 / 2.0 - z2 / 2.0 + y2 * z2 / 3.0); s.y = v.y * sqrt(1.0 - x2 / 2.0 - z2 / 2.0 + x2 * z2 / 3.0); s

Is there any MathParser that parse a mathematical string expression containing average function like avg(value1 + value2 + value3) + …?

99封情书 提交于 2020-12-13 11:12:24
问题 I have a text box and I simply type a mathematical expression like: sin(1) + 2 + cos(5) + sqrt(5) and pass it to my MathParser class object and it returns me the result. I went through the class and found that for mathematical operators like +, -, *, /; there is a function which returns 2 because these operations can be performed only between two parameters like '1 + 2' and mathematical functions like sin, cos, tan, abs, sqrt; have a single parameter like sin(param), etc. so it returns 1. Now

Pillow ImageDraw text coordinates to center

余生颓废 提交于 2020-12-08 10:41:22
问题 The code below brings the text in the center of x, but i don't know how to calculate the center for the y coordinate... it is not (imgH-h)/2! (The right y-coordinate is -80) from PIL import Image, ImageDraw, ImageFont font= './fonts/BebasNeue-Regular.ttf' color = (255, 244, 41) text = 'S' img = Image.new('RGB', (500, 500), color=(255, 255, 255)) imgW, imgH = img.size fnt = ImageFont.truetype(font, 600) d = ImageDraw.Draw(img) w, h = d.textsize(text, fnt) nullH = (imgH-h) print(imgH, h) d.text

Invert Number in C#

拈花ヽ惹草 提交于 2020-12-08 05:45:37
问题 Is there an easy way to invert a number in C# with a function? I'm using XNA and i'd like to tell my program that if my 'variable' gets beyond a certain number it has to invert it's value. The whole point is to give a rebound effect. if (ballPosition.X >= screenWidth) { // Invert the ball Direction Vector.X } 回答1: Just whack a - sign in front of it: direction.X = -direction.X; 回答2: or you can try using Vector.X * -1 来源: https://stackoverflow.com/questions/9765317/invert-number-in-c-sharp

How to compute the digits of an irrational number one by one?

£可爱£侵袭症+ 提交于 2020-12-06 16:56:43
问题 I want to read digit by digit the decimals of the sqrt of 5 in C. The square root of 5 is 2,23606797749979..., so this'd be the expected output: 2 3 6 0 6 7 9 7 7 ... I've found the following code: #include<stdio.h> void main() { int number; float temp, sqrt; printf("Provide the number: \n"); scanf("%d", &number); // store the half of the given number e.g from 256 => 128 sqrt = number / 2; temp = 0; // Iterate until sqrt is different of temp, that is updated on the loop while(sqrt != temp){ /

How to compute the digits of an irrational number one by one?

家住魔仙堡 提交于 2020-12-06 16:55:23
问题 I want to read digit by digit the decimals of the sqrt of 5 in C. The square root of 5 is 2,23606797749979..., so this'd be the expected output: 2 3 6 0 6 7 9 7 7 ... I've found the following code: #include<stdio.h> void main() { int number; float temp, sqrt; printf("Provide the number: \n"); scanf("%d", &number); // store the half of the given number e.g from 256 => 128 sqrt = number / 2; temp = 0; // Iterate until sqrt is different of temp, that is updated on the loop while(sqrt != temp){ /

How can you write an algorithm to properly fill a circle using lines from the center?

拜拜、爱过 提交于 2020-12-03 08:45:55
问题 Currently I try to write code for calculating the parts of the screen you can see and those who can't because of objects that block light in 2d, like in Among Us: The code should run on a processor with very low specs (at least in 2020), the C64. On such a simple CPU it's not possible to do such complex math fast enough for a game, so I came up with an idea: First of all, I make everything tile based, that makes processing easier and also means that I can just change entire characters or

numpy.sin function in degrees?

家住魔仙堡 提交于 2020-12-01 08:22:16
问题 I'm working on a problem that has to do with calculating angles of refraction and what not. However, it seems that I'm unable to use the numpy.sin() function in degrees. I have tried to use numpy.degrees() and numpy.rad2deg(). numpy.sin(90) numpy.degrees(numpy.sin(90)) Both return ~ 0.894 and ~ 51.2 respectively. Thanks for your help. 回答1: You don't want to convert to degrees, because you already have your number (90) in degrees. You need to convert 90 from degrees to radians, and you need to

numpy.sin function in degrees?

你说的曾经没有我的故事 提交于 2020-12-01 08:22:13
问题 I'm working on a problem that has to do with calculating angles of refraction and what not. However, it seems that I'm unable to use the numpy.sin() function in degrees. I have tried to use numpy.degrees() and numpy.rad2deg(). numpy.sin(90) numpy.degrees(numpy.sin(90)) Both return ~ 0.894 and ~ 51.2 respectively. Thanks for your help. 回答1: You don't want to convert to degrees, because you already have your number (90) in degrees. You need to convert 90 from degrees to radians, and you need to