Math problem

Answer I found on the internet for leverage. Sorry, I'm going to post it in this thread for easy reference as I try to build this code.


When you pick up the end of a board, the torque required will be equal to the product of the force that you apply F1 times the distance to the center of rotation L1 which in this case is the other end of the board. If a crate is sitting on the board, the torque exerted by the crate will be equal to the product of the crate's weight F2 and its distance from the center of rotation L2. These two torques must be equal in order for you lift the end of the board. Mathematically this turns out as
F1*L1=F2*L2
If you solve for F1 you will find out how much force F1 that you will need to apply to the end of the board which will be less than the actual weight F2 of the crate. For example assume the crate weighs 210 lb and is located 2 ft from the end of the board. Meanwhile you lift the other end of the board which is 6 ft long. You will then have to exert F1 = F2*L2/L1 = 210lb*2ft/6ft = 70lb.


so if I read this right
24etcsj.jpg

assume the force generated by the paddle is equal to one so we can see the leverage component.

Anyone know if I should be measuring the segment from the paddle face, or the from the center of the fulcrum?
 
2lxwhgk.jpg


Here's where I'm at for today. I'm trying to devise the easiest method to check to see if the ball lies between the points made by the blue lines. I need a bong hit
 
It's just algebra. If I took the time to work it out I could get it.
It would be best to triangle it up and then use Trig.

If you are looking for perfect you have to factor in the curve at the end of the flipper.

You also may want to go here:

Physics Forum

Where the tech savvy physics genius resides...

Anyway, here is the closest I am getting for coding this.

Code:
// Vector is a class with 3 double vars and math functions to manipulate.
double Triangle::distance( Vector &p )
{
    // normal is the triangles normal vector
    return this->normal.dotProduct( p - this->mid ) / this->normal.getLength();
}

double Triangle::angleBetween( Vector &p )
{
    return asin( ( this->normal.dotProduct( p ) / ( this->normal.getLength() * p.getLength() ) ) );
}

// p is ball pos
// v is ball vel
// newball is the new position if collision
// radius is radius of the ball
bool Triangle::isPossible( Vector &p, Vector &v, Vector &newball, double radius )
{
    static double plen;
    static double len;
    static Vector vhat;
    static Vector pv;
    
    // current position plus velocity
    // this will be the new position if there wasn't a hit
    pv = p + v;

    // unit of velocity
    vhat = v.normalize();

    // VZERO 1e-9
    if ( fabs( this->normal.dotProduct( vhat ) ) <= VZERO )
    {
        return false;
    }

    // length of ball from plane
    plen = this->distance( p );

    // length of new position from plane
    len = this->distance( pv );

    if ( plen >= radius && len < radius )
    { 
        newball = pv - ( vhat * fabs( ( radius - len ) / sin( this->angleBetween( -v ) ) ) );

        return true;
    }

    return false;
}

And the new Velocity would be factored in this way:

// d is the magnitude of the new velocity
// if vel magnitude was 20 but we only moved 15
// then the new magnitude is of length 5
this->vel = ( ( tri->normal *
tri->normal.dotProduct( -this->vel ) *
2.0 ) +
this->vel ).normalize() * d;

However, none of this is perfect because it doesn't factor in friction or gravity, nor the placement of the ball at the tip of the triangle (yours is a curve).

:dunno:

It's been a long time....

If I were you I'd hit the collective brain of the physics forum...

:D
 
thanks for the code Mr.C. Yeah I'm putting together a post for the physic forum and trying out the stuff here first.

You have t remember this is javascript and it's not very fast so we can get away with skipping the curve and just use the triangle for the field test. All I need it for it see if the ball is inside the triangle. I'll see if i can sort out the code you posted.

The code I need to make will be something like this

var CanHit=(ball.x<= right face)and (ball.x>=left face)and (ball.y>=point B)and (ball.y<=bottom face)
 
thanks for the code Mr.C. Yeah I'm putting together a post for the physic forum and trying out the stuff here first.

You have t remember this is javascript and it's not very fast so we can get away with skipping the curve and just use the triangle for the field test. All I need it for it see if the ball is inside the triangle. I'll see if i can sort out the code you posted.

The code I need to make will be something like this

var CanHit=(ball.x<= right face)and (ball.x>=left face)and (ball.y>=point B)and (ball.y<=bottom face)
That's my code, not Watermarks...

:p
 
var CanHit=(ball.x<= right face)and (ball.x>=left face)and (ball.y>=point B)and (ball.y<=bottom face)
That function describes a rectangular bounding box. Try using the distance function in combination with angles to describe the bounds of the circular section "hittable area.".

Let
X= paddle pivot point x coordinate
Y= paddle pivot point y coordinate
x1 = ball x coord
y1 = ball y coord

distance = sqrt [(X-x1)^2 + (Y-y1)^2]

When distance is less than paddle length, and angle from pivot to ball is between permissible angles, then hittable. Angle from pivot point to ball can be found using ATAN [(Y-y1)/(x-x1)] and compared to allowable values.

Also, need to correct for ball diameter; I edit that in later.
 
Last edited:
That function describes a rectangular bounding box. Try using the distance function in combination with angles to describe the bounds of the circular section "hittable area.".

Let
X= paddle pivot point x coordinate
Y= paddle pivot point y coordinate
x1 = ball x coord
y1 = ball y coord

distance = sqrt [(X-x1)^2 + (Y-y1)^2]

When distance is less than paddle length, and angle from pivot to ball is between permissible angles, then hittable. Angle from pivot point to ball can be found using ATAN [(Y-y1)/(x-x1)] and compared to allowable values.

Also, need to correct for ball diameter; I edit that in later.

Yeah, my first thought was to treat the paddle like a big sphere. But the problem is we're dealing with javascript and any extra computations will kill performance. So what I'm doing is trying to chop the slice of the testing field so less computations are used if the ball is not hitable. I'm thinking the distance function will also handle the leverage compnet of the force calulation.

Be back later. Thanks for the help.
 
Yeah, my first thought was to treat the paddle like a big sphere. But the problem is we're dealing with javascript and any extra computations will kill performance. So what I'm doing is trying to chop the slice of the testing field so less computations are used if the ball is not hitable. I'm thinking the distance function will also handle the leverage compnet of the force calulation.

Be back later. Thanks for the help.

Use assembly language for efficiency.
 
Looky what I found!! I forgot about this script I saved a while back.
http://h1.ripway.com/tinyscript/inpoly.html
right click and save the source to a txt file and save it as an .html file and you can mess with it
I think I can add more points to the test area and use this polygon test. I'm going to add one more point in the middle of the paddle arc so I'll be testing a polygon
 
NO ONE encodes in assembly language anymore USC. Although it's technically faster, processors these days are so fast you'd have to be crazy to waste the huge amount of time it would take more to code something in assembly on something as processor un-intensive as a pinball game. And anything that actually uses enough processor power to benefit from the speed increase provided by assembly coding is so complicated you'd also have to be crazy to even make the attempt.
 
USC
I would use flash but I don't know the action script language yet.

Javascript is good to learn basic programing techniques, my main goal, without needing to compile code to experiment. All I have to do is modify the HTML file in a txt page and then save the changes. click on the HTML and it runs. No compiling.

Also firefox has javascript console to help you find errors.
 
The purpose of this game is have it play online in a web page. It's going to be a unique web application. It's not a game worth creating in a traditional computer language. The neato part is the dealing with limited resources.

here's the flippers
http://h1.ripway.com/tinyscript/canvasPinballFlippers.html

here's the pinball game so far.
http://h1.ripway.com/tinyscript/pinballRedux.html

Assembly language is for limited resources.
Java, C+++++, etc are for high memory and horse power computers.

I have noticed that the inefficiency of code is inversly proportional to speed increases in computer hardware.

The first computer I programmed on was a commercial mini and had a whopping 16K of mag core ram.
Punched the prog into a paper tape to load it in. Or direct punched binary into it.
 
Last edited:
Assembly language is for limited resources.
Java, C+++++, etc are for high memory and horse power computers.

I have noticed that the inefficiency of code is inversly proportional to speed increases in computer hardware.

The first computer I programmed on was a commercial mini and had a whopping 16K of mag core ram.
Punched the prog into a paper tape to load it in. Or direct punched binary into it.
Liar, you slid beads from one side of the abacus to the other.

;)
 
Back
Top