math

Calculate angle change after hitting a tilted wall

我的未来我决定 提交于 2021-02-08 08:21:33
问题 I'm making a game in javascript, where an object is supposed to bounce from walls. I really tried to get it to work myself, but it never works correctly. Let's say theres a ball bouncing inside this cage (blue = 30°, brown = 60°); The ball's coordinates are known. The angle of movement is known. The point of collision (P) coordinates are known. The angle of the wall is known. The ball's position is updating it's coordinates inside a setInterval function using this function: function

Spot it algorithm - js

ⅰ亾dé卋堺 提交于 2021-02-08 05:17:33
问题 In the game Dobble ( "Spot it") , there is a pack of 57 playing cards, each with 8 different symbols on them. The system is that any two cards chosen at random will have just one matching symbol. This spurred me on to the mathematical background behind the system and so I wrote an simple algorithm: let getCards = function(symbolCount) { let n = symbolCount - 1, cards = [], card = [] for (i = 0; i < n + 1; i++) card.push(i) cards.push(card) for (j = 1; j <= n; j++) { let card = [1] for (k = 1;

Why gradient of tanh in tensorflow is `grad = dy * (1 - y*y)`

倖福魔咒の 提交于 2021-02-08 04:46:24
问题 tf.raw_ops.TanhGrad says that grad = dy * (1 - y*y) , where y = tanh(x) . But I think since dy / dx = 1 - y*y , where y = tanh(x) , grad should be dy / (1 - y*y) . Where am I wrong? 回答1: An expression like dy / dx is a mathematical notation for the derivative, it is not an actual fraction. It is meaningless to move dy or dx around individually as you would with a numerator and denominator. Mathematically, it is known that d(tanh(x))/dx = 1 - (tanh(x))^2 . TensorFlow computes gradients

Creating a custom cumulative sum that calculates the downstream quantities given a list of locations and their order

╄→尐↘猪︶ㄣ 提交于 2021-02-08 04:41:42
问题 I am trying to come up with some code that will essentially calculate the cumulative value at locations below it. Taking the cumulative sum almost accomplishes this, but some locations contribute to the same downstream point. Additionally, the most upstream points (or starting points) will not have any values contributing to them and can remain their starting value in the final cumulative DataFrame. Let's say I have the following DataFrame for each site. df = pd.DataFrame({ "Site 1": np

how to calculate a^(b^c) mod n? [duplicate]

时光毁灭记忆、已成空白 提交于 2021-02-08 04:37:27
问题 This question already has answers here : finding a^b^c^… mod m (6 answers) The most efficient way to implement an integer based power function pow(int, int) (17 answers) Closed 6 years ago . Can someone tell me the efficient way to solve this problem ? a b c mod m a, b, c, and m are 32 bit int where m is not a prime number and a is not coprime to m ?I've looking for the answer, but haven't found it There are some answered questions that familiar with this question, but none of them can

Strange Error: ZeroDivisionError: float division by zero

无人久伴 提交于 2021-02-08 02:32:23
问题 I found a strange behavior and hope someone has an explanation for it. I'm doing: if len(list) > 1 and len(list2) > 1: total = sum(list) + sum(list2) result = percentage(sum(list), total) def percentage(part, whole): return float(part) / float(whole) *100 The two lists are a mix of float and int values. I sporadically get: ZeroDivisionError: float division by zero This doesn't makes sense to me. Does anyone have an idea what's happening? 回答1: The problem is obvious if you print out the values

Strange Error: ZeroDivisionError: float division by zero

两盒软妹~` 提交于 2021-02-08 02:31:07
问题 I found a strange behavior and hope someone has an explanation for it. I'm doing: if len(list) > 1 and len(list2) > 1: total = sum(list) + sum(list2) result = percentage(sum(list), total) def percentage(part, whole): return float(part) / float(whole) *100 The two lists are a mix of float and int values. I sporadically get: ZeroDivisionError: float division by zero This doesn't makes sense to me. Does anyone have an idea what's happening? 回答1: The problem is obvious if you print out the values

Find point with vector projection

ぐ巨炮叔叔 提交于 2021-02-07 23:14:03
问题 I am trying to work this out in java with LatLng point I was looking at this post here Circle line-segment collision detection algorithm? I have a method to find distance between 2 point. The instruction says Project the vector AC onto AB. The projected vector, AD, gives the new point D. If the distance between D and C is smaller than (or equal to) R we have an intersection. I don't have knowledge about vector, could anyone help me how to find point D here ? Thanks in advance 回答1: If you

Given a line in 3D space, how do I find the angle from it to a point?

穿精又带淫゛_ 提交于 2021-02-07 21:10:31
问题 I have two sets of points in 3D space. I'd like to draw a line that runs through the center of both sets of points, and then find the angle from that line to each point. From there, I'll match points in the two sets up based on how close together their two angles are. I know how to find the center of each set of points (just average them all together) and I know how to match them up (even accounting for the fact they'll wrap around), but I don't know how to find the angle from the line to the

How to detect collisions with a curve

大憨熊 提交于 2021-02-07 20:15:53
问题 I am making an HTML5 and Javascript platform game. At this moment all blocks of the map are handled as squares. This method is "ugly" when the block is not an exact square/rectangle. Check this image I made to get a better understand of my point: Case one: The "bottom bumper" is touching the square that envolves the block so the movement is stopped. Case two: If I use the same method as above, when the players jumps, the movement will be stopped before the "top bumper" even touches the block.