Ball collision time with ceiling
I know to to do collision time with the ground. Here's how I calculate that: gravityY = positive 9.81
float timeToGround = (velocity.y + Sqrt(velocity.y*velocity.y + 2f * gravityY * distanceToGround)) / gravityY;
How do I calculate the collision time to the roof/ceiling based on distance and initial velocity?
float timeToRoof = ?
I don't know where to look, thanks so much for your help
2 answers

You need to solve quadratic equation for unknown time t
h = y0 + Vy * t  g*t^2 / 2 or g*t^2/2  Vy*t + (hy0) = 0 // a,b,c coefficient grouped
for known height of starting point y0, roof height h, gravity g, ycomponent of initial velocity Vy

Hehe, thanks for your help. Here's the answer:
float timeToRoof = (velocity.y + Sqrt(velocity.y * velocity.y + 2f * gravity.y * distanceToRoof)) / gravity.y;
 gravity.y = negative 9.81
 velocity.y = current velocity
 distanceToRoof = current distance to roof
See also questions close to this topic

Problem Defining Variable in Python Net Worth Update Function
I am trying to write code that will allow someone to input original net worth, input a change and receive updated net worth but I am having trouble with one of the variables, everything else works. Any help would be appreciated.
def net_worth_updater(): print("This tool will allow you to enter your last known net worth and a value that has changed and your net worth will be updated for you.") def update(): net_worth = int(input("What is your last known net worth? ")) type1 = input("Is the change in the category asset or liability? ") if type1 == "asset": first = int(input("Input Original Value ")) second = int(input("Input New Value ")) change = second  first net_worth = net_worth + change return net_worth else: first = int(input("Input Original Value ")) second = int(input("Input New Value ")) change = second  first net_worth = net_worth  change return net_worth while input("Would you like to report a change? ") == "yes": update() print("Your updated net worth is $" + str(net_worth))
When I'm running the code the net_worth variable fails out at the end.

StackOverflowException when I call the same function many times
I am creating a function that creates a point in specific coordinates, which calls itself moving to each of the cardinal points (until a spicific limit).
I have a StackOverflowException error when more than 5000 positions are stored.
More easy: I have created points with coordinates moving only to the north and still giving the same error
*NorthLimit, LatitudeDeviation and LongitudeDeviation are constants.
public void CreatePosition(decimal latitude, decimal longitude) { boolean end = true; Positions.Add(new Position(latitude, longitude)); if (NorthLimit > (latitude + LatitudeDeviation)) { CreatePosition(latitude + LatitudeDeviation, longitude); end = false; } if (end == true) { // It ends :) } }
What measures should I take?

Implementing a generic mathematical operaton in Rust
What's the right way to implement this Rust function using generic types?
pub fn div_round_up<T>(a: T, b: T) { (a + b  1) / b }

(2d Square Collision Detection) Moving objects apart when they collide stuttering
I have looked everywhere for some tips on collisions detection but i cant really seem to find anything that makes sense to me or works in my case. I understand how to detect if two square shapes are colliding or not but i dont understand what to do in terms of separating them the correct way with gravity and what not applied to them.
if (tile>position.x < other>position.x + Tile::size && tile>position.x + Tile::size > other>position.x && tile>position.y < other>position.y + Tile::size && tile>position.y + Tile::size > other>position.y) { glm::vec3 tCenter = tile>getCenter(); glm::vec3 oCenter = other>getCenter(); glm::vec3 dir = tCenter  oCenter; dir.x = dir.x / (Tile::size / 2.0f); dir.y = dir.y / (Tile::size / 2.0f); tile>position += dir; tile>velocity *= 0.0f; }
So basically if a collision happens then move them apart. I came up with this method after reading a few things online. This is super close but there is some stuttering that i cant seem to figure.
Does anyone know what i am missing or can you point me in the right direction?

How can i get rid of an object after a collision in pygame?
I have created a program which makes squares bounce all around the screen. Every time they make contact with the player, they disappear (i change their location so that they are outside the display) and therefore cannot be seen by the user. Is it possible to not only change their location but also to completely get rid of them so that the CPU doesn't have to process them.
Thank you very much!
import pygame import random import sys import time Height = 800 Width = 800 Steps = 0 running = True Number = 2000 x = 0 BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) pygame.init() display = pygame.display.set_mode((Height, Width)) clock = pygame.time.Clock() pygame.display.set_caption("Game") class Ball(object): def __init__(self, ball_pos_x, ball_pos_y, ball_height, ball_width, delta_x, delta_y): self.ball_pos_x = ball_pos_x self.ball_pos_y = ball_pos_y self.ball_height = ball_height self.ball_width = ball_width self.delta_x = delta_x self.delta_y = delta_y def draw(self): pygame.draw.rect(display, WHITE, (self.ball_pos_x, self.ball_pos_y, self.ball_height, self.ball_height)) def update(self): self.ball_pos_x += self.delta_x self.ball_pos_y += self.delta_y if self.ball_pos_x < 0: self.delta_x = self.delta_x * 1 if self.ball_pos_x > Width  self.ball_width: self.delta_x = self.delta_x * 1 if self.ball_pos_y < 0: self.delta_y = self.delta_y * 1 if self.ball_pos_y > Height  self.ball_height: self.delta_y = self.delta_y * 1 class Player: def __init__(self, player_height, player_width, pos_x, pos_y, player_vel): self.player_height = player_height self.player_width = player_width self.player_vel = player_vel self.pos_x = pos_x self.pos_y = pos_y self.rect = self.pos_x def draw(self): pygame.draw.rect(display, BLUE, (self.pos_x, self.pos_y, self.player_height, self.player_width)) def update(self): keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and self.pos_x > 0: self.pos_x = self.player_vel if keys[pygame.K_RIGHT] and self.pos_x < Width  player.player_width: self.pos_x += self.player_vel if keys[pygame.K_UP] and self.pos_y > 0: self.pos_y = self.player_vel if keys[pygame.K_DOWN] and self.pos_y < Height  player.player_height: self.pos_y += self.player_vel def collision(self): pass player = Player(10, 10, Width/2, Height/2, 5) """ keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and x > 0: x = vel if keys[pygame.K_RIGHT] and x < 800  30: x += vel """ list = [] for i in range(Number): ball = Ball(random.randrange(0, Width  10), random.randrange(0, Height  10), 10, 10, random.randint(10, 10), random.randint(10, 10)) list.append(ball) while running: display.fill(BLACK) clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() # Update # Draw for ball in list: ball.draw() ball.update() if (ball.ball_pos_x >= player.pos_x  ball.ball_width and ball.ball_pos_x <= player.pos_x + player.player_width and ball.ball_pos_y >= player.pos_y  ball.ball_height and ball.ball_pos_y <= player.pos_y + player.player_height): ball.ball_pos_x = 20 ball.delta_x = 1 x += 1 print(x) player.draw() player.update() pygame.display.flip() pygame.quit()

How detect collision with kinematic 2d rigidbody
I am making a 2d game but there is problem with collision detection with kinematic rigidbody. Sometime it detect the collision but mostly it never detect the collision. Actually I am making a replica of Knifehit game.In which when a knife hit with the Target Object then it will be the child of that object and moving with him in a circle.So whenever a knife hit with another knife then it never detect the collision because of (Kinematic Rigidbody). I have attached 2D box collider on knifes but it not work fine. Here are some pic of game.
So when I hit The knife with candy Then knife will become the child of candy and body type of knife is changed from (Dynamic to kinematic) so the knife start moving with the candy but when knife hit with another knife it never find the collision detection so how can fix it.Please sir help me.

How do you access Gravity Form fields presubmission?
I'm trying to access the Gravity Forms fields presubmission to check for gibberish entries. I've tried pretty much everything on StackOverflow and no luck.
The form is id #1. Some of the 1000 things I've tried include:
GFFormsModel::get_form_meta(1); GFFormsModel::get_leads(1); $_POST['input_1']
and reading this: https://docs.gravityforms.com/gform_pre_submission/
How do I do this?

Implementing a RungeKutta 4 method for 3 body problem in Python
I'm trying to implement an RK4 method in Python to solve for the Sun, Earth and Jupiter system. This code works for Halley's comet, when I have 4 ODEs to solve instead of 8, I've tried extending my method to 8 ODEs but now I just keep getting a straight line and have no idea why. Can someone please point out to me the stupid mistake I'm making, because I'm stumped as to why this isn't working. Here's the code:
import math import numpy as np import matplotlib.pyplot as plt G = 6.67e11 M = 1.989e+30 #mass of the sun m1 = 5.972e+24 #mass of planet 1 m2 = 1.898e+27 #mass of planet 2 AU = 1.496e+11 a1 = 1.0*AU #distance from planet 1 to the sun a2 = 5.2*AU #distance from planet 2 to the sun #A = (G*M)/(a1**3) #B = (G*M)/(a2**3) ##C = G/(abs(a2  a1)**3) # #print("A = ", A, "B = ", B) x_i1 = a1 #initial values for planet 1 in x and y direction y_i1 = 0.0 v_x1i = 0.0 v_y1i = 3e+4 x_i2 = a2 #initial values for planet 2 in x and y direction y_i2 = 0.0 v_x2i = 0.0 v_y2i = 13.07e+3 t_upper = 365*24*3600 #run the program to simulate a year t = 0.0 t_i = 0.0 N = 10000 def f1(r, t): #function containing the relevant equations and arrays x1 = r[0] #storing position and velocity components in x and y direction for planet 1 y1 = r[2] v_x1 = r[1] v_y1 = r[3] x2 = r[4] #storing position and vecloity components in x and y direction for planet 2 y2 = r[6] v_x2 = r[5] v_y2 = r[7] C = G/(((x1  x2)**2 + (y1  y2)**2)**1.5) #equations for 3 body problem, just to condense the maths D = G/(((x2  x1)**2 + (y2  y1)**2)**1.5) A = (G*M)/(a1**3) B = (G*M)/(a2**3) dvx1 = (A*x1) + ((C*m2)*(x1  x2)) #Acceleration in x and y for each planet dvy1 = (A*y1) + ((C*m2)*(y1  y2)) dvx2 = (B*x2)  ((D*m1)*(x2  x1)) dvy2 = (B*y2)  ((D*m1)*(y2  y1)) return np.array([v_x1, dvx1, v_y1, dvy1, v_x2, dvx2, v_y2, dvy2]) #return array storing all the differential equations we want to solve r = np.array([x_i1, v_x1i, y_i1, v_y1i, x_i2, v_x2i, y_i2, v_y2i], float) #define array with initial values x_pnts1 = [x_i1] #array containing the position in x for planet 1 v_x_pnts1 = [v_x1i] #array containing the velocity in x for planet 1 y_pnts1 = [y_i1] #position in y for planet 1 v_y_pnts1 = [v_y1i] #velocity in y for planet 1 x_pnts2 = [x_i2] #same as above, but for planet 2 v_x_pnts2 = [v_x2i] y_pnts2 = [y_i2] v_y_pnts2 = [v_y2i] t_values = [t_i] h = t_upper/N while t < t_upper: k1 = h*f1(r, t) #RK4 routine, using the function defined above k2 = h*f1(r + 0.5*k1, t+h/2) k3 = h*f1(r + 0.5*k2, t+h/2) k4 = h*f1(r + k3, t+h) r += (k1 + 2*k2 + 2*k3 + k4)/6 x_pnts1.append(r[0]) #append the relevant arrays with the values from the RK4 routine v_x_pnts1.append(r[1]) y_pnts1.append(r[2]) v_y_pnts1.append(r[3]) x_pnts2.append(r[4]) v_x_pnts2.append(r[5]) y_pnts2.append(r[6]) v_y_pnts2.append(r[7]) t += h t_values.append(t) aphelion_e = np.max(x_pnts1) perihelion_e = abs(np.min(x_pnts1)) print("Perihelion of earth = ", perihelion_e/AU, "AU") print("Aphelion of earth = ", aphelion_e/AU, "AU") plt.plot(x_pnts1, y_pnts1) plt.plot(0, 0, "o", 15) plt.show()

Get joint angles between segments of a robot arm using IMU data
I have an IMU attached to each of the segments of a robotic arm, which gives me accelerometer data, gravity and gyroscope data. How can I calculate the angles between each of the joints using this data?