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

Write a recursive function with multiplicating factor
I'm trying to write a recursive function with a multiplication factor. I'm not very experienced with recursion so there is the logic
x = foo x+1 = foo * factor x+2 = x+1 * factor x+3 = x+2 * factor . . . y = x+n * factor
I'm struggling to find the math logic behind it, and I don't know if it is even possible to write it with a recursive function...

Converting a given formula to vb.net
I have a given mathematical formula that I need to translate to VB.NET code, but I am not getting the expected result. As I found in the documentation, I have to convert the angle so that
Math.Sin
works correctly.Dim locC1 = 1 Dim locC2 = 0.5 Dim locA1 = 30 Dim locA2 = 60 Dim locOldAxisToAngleConversion = (Math.PI / 180) * locA1 Dim locNewAxisToAngleConversion = (Math.PI / 180) * locA2 Dim locCylSinus1 = locC1 * Math.Sin(2 * locOldAxisToAngleConversion) Dim locCylSinus2 = locC2 * Math.Sin(2 * locNewAxisToAngleConversion) Dim locCylCosinus1 = locC1 * Math.Cos(2 * locOldAxisToAngleConversion) Dim locCylCosinus2 = locC2 * Math.Cos(2 * locNewAxisToAngleConversion) Dim locFraction = (locCylSinus1 + locCylSinus2) / (locCylCosinus1 + locCylCosinus2) Dim locNewAxis = 0.5 * Math.Atan((Math.PI / 180) * locFraction) Return Convert.ToInt32(locNewAxis)
The result of the given data should be 39.6, but I'm unable to obtain it.

Using SymPy to find differential equation in new coordinate system (after rescaling)
In my work, a common task is to rewrite differential equations in new coordinate systems (rescaling both the coordinates and the functions). As the calculations can get rather tedious, I would like to automate this with SymPy.
Below is a simplified example, which (hopefully) shows what I want to achieve. NOTE: I am not interested in trying to solve the ODE  all I care about are the coefficients in the new coordinate system.
So, given the original ODE:
and the scaling relations:
and
I would like to use SymPy to get to the new ODE:
Below is some code with what I tried (without getting too far). If I
import sympy as sp sp.init_printing(use_unicode=True) # define symbols for original coordinate & constants x, alpha, beta, gamma = sp.symbols('x alpha beta, gamma', real=True, positive=True) # define symbol for original function u = sp.Function('u', real=True)(x) original_ode = sp.Eq(u.diff(x) + alpha, 0) # define symbol for new coordinate x_d = sp.symbols('x_d', real=True, positive=True) # define symbol for new function (in the new coordinate system) u_d = sp.Function('u_d', real=True)(x_d) # define scaling relations (for transfer to x_d coordinate) #x_d = x / beta #u_d = u / gamma # u_d is the new function (int the new coordinate system) # TODO: find out how to obtain the ODE for u_d(x_d) expected_ode = sp.Eq( # < I would like to derive this equation, # instead of writing it manually u_d.diff(x_d) + (alpha*beta)/gamma, 0 ) expected_ode

ARKit Physics Objects Phasing through tracked planes
I am currently trying to modify the plane tracking demo that apple provided to have little cube projectiles bounce off the tracking planes that the app creates.
I have added physics bodies to the respective projectile and wall, but for some reason the projectile continues to ignore the collisions and just phases through the wall. I have tried adding and removing the bit masks, but they don't seem to affect anything.
Here is what I am currently doing for my tracked planes:
init (anchor: ARPlaneAnchor, in sceneView: ARSCNView) { guard let meshGeometry = ARSCNPlaneGeometry(device: sceneView.device!) else { fatalError("CANNOT CREATE GEOMETRY") } meshGeometry.update(from: anchor.geometry) meshNode = SCNNode(geometry: meshGeometry) meshNode.name = "ENV." super.init() self.setupMeshVisualStyle() let body = SCNPhysicsBody(type: .static, shape: nil) meshNode.physicsBody = body addChildNode(meshNode) }
Here is the bullet physics implementation
class func spawnBullet() > SCNNode { // Omitted code (just setting size and stuff) let cubeNode = SCNNode(geometry: cubeGeometry) cubeNode.name = "BULLET" let physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.dynamic, shape: nil) physicsBody.isAffectedByGravity = false physicsBody.damping = 0 physicsBody.categoryBitMask = CollisionCategory.bullet.rawValue physicsBody.collisionBitMask = CollisionCategory.env.rawValue  CollisionCategory.player.rawValue physicsBody.continuousCollisionDetectionThreshold = 0.01; cubeNode.physicsBody = physicsBody return cubeNode }
I have created a separate SCNPlane object with the exact same physics body settings as the tracked plane settings. What's odd is that the bullets successfully collide off of the SCNPlane, but they continue to pass through the tracked planes with the exact same settings.

detect collision of objects in ArrayList with them selfs (just like a snake)
i'm making Tron LightCycle game (it's a basic game where you have to overthrow the second player using your lightcycle) , I've run into a problem when detecting collision between the player and his Lightcycle check the image
This is the Lightcycle class:
public class Lightcycle { private int xCor , yCor , width , height ; public Lightcycle(int xCor , int yCor , int tileSize , int tile) { this.xCor = xCor; this.yCor = yCor; this.width = tileSize ; this.height = tile ; } public void tick() { } public void render(Graphics g) { g.setColor(Color.red); g.fillRect(xCor, yCor, width, height); } public int getxCor() { return xCor; } public void setxCor(int xCor) { this.xCor = xCor; } public int getyCor() { return yCor; } public void setyCor(int yCor) { this.yCor = yCor; } public Rectangle getBounds() { return new Rectangle((int) xCor ,(int) yCor, 18, 19); } }
The player class:
public class Player extends Entity { private Game game; private int dir = 0; /* dir = 0 Normal State * dir = 1 Up State * dir = 2 Down State * dir = 3 Reverse State */ public Player(Game game,float x , float y) { super(x, y); this.game = game; } public void tick() { if(game.getKeyManager().up) { y = 2; } if(game.getKeyManager().down) { y += 2; } if(game.getKeyManager().right) { x += 2; } if(game.getKeyManager().left) { x = 2; } } public void render(Graphics g) { g.drawImage(Assets.player1,(int) x,(int) y, 18,19,null); } public Rectangle getBounds() { return new Rectangle((int) x,(int) y, 18, 19); } public Rectangle getBounds2() { return new Rectangle((int) x + 20 ,(int) y, 18, 19); } public int getX() { return (int) x; } public int getY() { return (int) y; } public void playerStop() { } }
This is the ArrayList:
Light = new ArrayList<Lightcycle>();
Here i add an object in the ArrayList:
if(game.getKeyManager().moving) { Light.add(new Lightcycle(xCor, yCor, size , sizze)); score++; }
Collision Check :
for(int i = 0 ; i <Light.size() ; i++) { if(player.getBounds().intersects(Light2.get(i).getBounds())  player.getBounds().intersects(Light.get(i).getBounds())){ game.stop(); }

How to solve clumping issues at elastic shock simulation?
I am writing an elastic shock simulation for multiple balls. First i recognize if an collision would have happen if the balls move the next time. Than i calculate the new velocity for every collision pair and move all the balls that would not collide. I am using the formula from Wikipdia ( https://en.wikipedia.org/wiki/Elastic_collision#Twodimensional_collision_with_two_moving_objects ) and i think my calculations are all right. The problem is that if more than two balls collide at the same update cycle, there is a change they clump up in piles and stop moving. The velocity vectors (black lines in picture) do swap between two different states after they are clumbed. I must have a logical problem here and i can not find it.
I allready tried to:
 randomice in wich order the collisions get calculated
 do one of the conected collisions at a time at different update cycles
 do only one collision at one update cycle
The update function:
public void update() { List<Ball> ballsToUpdate = new ArrayList<>(balls); Map<Ball, HashSet<Ball>> collisionPairs = new HashMap<Ball, HashSet<Ball>>(); // Get the pairs of colliding balls for (Ball ball : ballsToUpdate) { for (Ball ball2 : ballsToUpdate) { if (ball.equals(ball2)) { continue; } if (Ball.collision(ball.getNextPosition(), ball.getRadius(), ball2.getNextPosition(), ball2.getRadius()) && !(collisionPairs.containsKey(ball2) && collisionPairs.get(ball2).contains(ball))) { if (collisionPairs.containsKey(ball2)) { collisionPairs.get(ball2).add(ball); } else { if (collisionPairs.get(ball) == null) { collisionPairs.put(ball, new HashSet<>()); } collisionPairs.get(ball).add(ball2); } } } } // Do the elastic shocks HashSet<Ball> collided = new HashSet<>(); for (Ball key : collisionPairs.keySet()) { for (Ball ball2 : collisionPairs.get(key)) { Ball keyCopy = new Ball(key); key.elasticShock(ball2); // uses formula from wikipedia ball2.elasticShock(keyCopy); collided.add(key); collided.add(ball2); } } // Check for border collision and move all balls that did not collid for (Ball ball : ballsToUpdate) { if (!collided.contains(ball) && Ball.collisionWithBounderies(width, height, ball.getNextPosition(), ball.getRadius())) { ball.setForceDirection(ball.getForceDirection().negate()); //placeholder } else if (!collided.contains(ball)) { ball.move(); // Moves the ball to the next position } } }

is there R codes to filter and convert GRACE geoid coefficients into equivalent water height(mm)
I'm trying to get the groundwater height of an area uisng GRACE geoid coefficients. firstly, saw some codes on github, following the repo, There is a need to compile fortran codes using intel compiler, which i found bit difficult to compile.

gform_after_submission syntax to send data to second table
I am using a 3rd party plugin which creates a custom post, and stores some of the post fields in a custom table. I am also using Gravity Forms to submit the custom post type, but cannot get the necessary field data into the plugincreated table.
All the relevant standard fields in the custom post type are populated on submission of the Gravity Form just fine, when stored in the standard tables. Some custom fields are also populated correctly which is being done by using GF Post Fields > Custom Field in the form, from which the correct custom field is selected for each form field.
The problem is the 2 fields which are sent by the plugin to a different table. I simply cannot get these to populate. Here is the code I am using, where "wc_locations_relationships" is the table name, and "location_id" and "address_field_1" are the field names.
add_action('gform_after_submission_2', 'wc_add_entry_to_db', 10, 2); function wc_add_entry_to_db($entry, $form) { $source = $entry['source_url']; $wccountry = $entry['30']; $wcaddressline1 = $entry['24']; global $wpdb; // add form data to custom database table $wpdb>insert( 'wc_locations_relationships', array( 'source_url' => $source, 'location_id' => $wccountry, 'address_line_1' => $wcaddressline1 ) ); }
When I submit the form, it is posted correctly, and appears in the plugin post list in admin. With regards to the code above, there are no errors, and nothing appears in those fields in the post created by the plugin. The standard WP title field and others not sent to the second table all populate correctly.
All help greatly appreciated, as this is definitely not my strong point where WP is concerned.

Same jumpheight with changing gravity
I am trying to recreate the googlechrome offline Dino game. In this game the Dino has a gravitypull on himself and it has a jump velocity, an upwards speed applied when the user presses the space bar.
Over time the obstacles move faster and faster to the player. When the obstacles move faster the Dino's jump should also be faster.
I tried to make a faster jump by increasing the gravity over time, so the Dino gets pulled down faster. But how do I get the Dino to jump the same height, let's say, 50 pixels upwards, no matter what the gravity is.
I tried working with the formula's: y = 0.5*a*t^2 + v(0)*t But I can't come to a correct answer.
The canvas this code is working as regards the top left corner as the origin(0,0). Therefore the jump velocity is negative and the gravity is positive.
This code is inside the Dino class, where this references to the Dino. In the constructor of the Dino class I have the code
this.y = 0; this.vy = 0; this.gravity = 1; this.speed = 0;
In the update function that is called each x amount of time:
this.speed += 0.001; this.y += this.vy; this.vy += this.gravity; this.gravity += speed*0.001;
The jump function executes when the spacebar is pressed:
this.vy = (?);
The amount of pixels the dino jumps gets higher over time. How could I make the Dino jump the same amount of pixels every time no matter the gravity?