Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have four points that make concave quad:
a(3 , 11)
b(11 , 9)
c(18 , 10)
d(8 , 1)
now i wanna get the inner angle of the (b) corner in degrees.
note: the inner angle is greater than 180 degree.
The safest way is to use inner product and cross product , the inner product can be calculated using the 4 points of the two vectors ( a->b , b->c) and using the inner product formula
<ab,bc> = |ab|*|bc|* cos (abc)
cos(abc) = |ab|*|bc| / <ab,bc>
this is not enough to allocate the angel uniquely since an angle and its complement has the same cos but has different sins , and here is where the cross product comes to solve the problem
ab * bc = |ab|*|bc| * sin(abc)
the left part can be calculated using ending points coordinates so you can calculate the sin , once sin and cos is calculated you can specify the angel appropriately .
Point d is just a distraction here. Consider the (abc) triangle:
It is easy to determine the length of ab, bc and ca from the coordinates.
you can then determine the (ab, bc) internal angle with sin, cos or tan
the angle you look for is 360 minus the (ab, bc) internal angle.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
So im making a wolfenstein 3d copy in Java and i've done a door list to change from 1 (closed) to 2(open) and i would want to make 2 to 1 when the player is not near it
ive got 2 variables for the player(yPos, xPos) and 2 for the door(row,column)
First of all, I think that "ibm-doors" is not a good tag for your question ^^
Actually, this is a math question. You can calculate the distance between the player and the door with this formula (you may adapt the variable names and operators to your needs):
playerDoorDistance = sqrt((player.xPos - door.xPos)^2) + (player.yPos - door.yPos)^2)
where sqrt is the square root of what is between brackets, and ^2 is the square of what is between brackets.
Once calculated, you can just check that this distance is greater than a value of your choice to close the door.
If you prefer something more simple and that requires less calculation, you can just verify that abs(player.xPos - door.xPos) and abs(player.yPos - door.yPos) are greater than your chosen value (abs is the absolute value of what is between brackets) to close the door. It will verify that your player is outside a squared box around the door.
If you want no math at all, you can check this, which is the same as above (you may also adapt it to your needs):
if (player.xPos - door.xPos > chosenValue || door.xPos - player.xPos > chosenValue || player.yPos - door.yPos > chosenValue || door.yPos - player.yPos > chosenValue)
then closeTheDoor()
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm looking into absolute function minimization problem in Java. Can anyone suggest libraries and solutions?
I downloaded apache common math3, however, could not find related functions to create linear function to minimize absolute functions.
Simply, I am looking into writing below functions in Java.
f(x) = b + | x - a | + d + | x - c | + f + | x - e |
I've edited this problem a bit for my second problem, here b, d, f are also linear functions.
b = a1x + b1
d = a2x + b2
f = a3x + b3
If you are summing N terms of the form |x - a_i|, consider the gradient as x increases from negative infinity:
At negative infinity, and for most of the left-hand number line, the gradient is -N;
As you pass the minimum of the a_i values, the gradient increases slightly, to -N+2;
As you pass the next smallest of the a_i values, the gradient increases again, to -N+4.
Each further a_i passed, the gradient increases by 2;
At positive infinity, the gradient is +N.
So, the gradient starts negative, increases in steps at each of the a_i positions, and ends up positive; you're looking for the point or range where the gradient is zero. This will occur "in the middle", i.e. at the median of the values a_i.
If there are an odd number of points, the median will be at a point. This is the case in the question: the minimum is at median(a, c, e).
If there are an even number of points, the median is between two points. In this case, the function is minimised anywhere between those points.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
I need to find the number of total possible different solution to an equation with more than one variable.
For example:
1x + 2y + 8z = 13
What is the total number of different combinations for the values of x, y and z?
I can't think of an algorithm to solve this. I don't need the answers printed, just the total number of different combinations. The coefficients and variables will always be positive, and the final number too.
1x + 2y + 8z = 13
Hence try (x, y,z) from (0, 0, 0) upto (13, 6, 1)
Hence at most 14*7*2 tries
Sort by the highest coefficient: z, y, x. The last variable can be inferred
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How would I go about programming a gravity simulator? I am making a kind of 2d space-simulator and what I want is to have a planet (a center of gravity) to pull objects towards it. The object is a spaceship (basically just x and y-coordinates).
Use Newton's laws - the forces two objects feel are attractive (from one objects mass center point to the other's), equal to each other, and in value equal to g*m1*m2/(d*d) (where g is a constant, m1 and m2 are the masses and d is the distance of the center points.
However, if you have a planet, the effect of the spaceship's attraction to the planet is negligible, so one usually does not do the computations for the planet; it's just stationary.
Keep in mind that F=m*a, where F is the force calculated above, m the mass of the spaceship and a is the acceleration of the object. Based on the acceleration you calculate the speed, and based on the speed the position.
Check out Princeton's N-Body assignment. It describes what you want.
However, in the interest of quick summaries, you can derive the equations from basic trigonometry and Newton's Law of Universal Gravitation:
F = GMm/(r^2)
where F = force between two objects, G = gravitational constant, M and m are the relevant masses, and r is the distance between them.
A little mathemagic and you get the following results:
F_x = F(x_2 - x_1)/r
F_y = F(y_2 - y_1)/r
where F_x is the gravitational force in the x direction (same for F_y, but in y direction), x_2 and y_2 is the position of one of your objects, x_1 and y_1 the position of the other, F is as defined above, and r is the distance between them.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am looking to simulate a jump for my Android game, however I have no clue how to achieve this properly. I have been looking up velocity a bit, but I just can't translate it to code myself. Looking for some demo code to get this worked.
The current height variable is called: centerY, this has 427 as default value. When you jump, it has to go to about 360 then go back to 427.
Thanks in advance!
To simplify things I'll assume jumping instantly accelerates the player. Here's some very basic pseudocode of how things should work. Note that you'll need to figure out a better way to handle ground collisions than a simple height check.
G := 9.8 or something other appropriate constant
defaultY := 427;
player {
var centerY
var velocityY
update(dt) {
if (centerY < defaultY)
velocityY += G * dt
centerY += velocityY
else
velocityY := 0
centerY := defaultY
}
jump() {
dh := 427 - 360
velocityY := -sqrt(2 * G * dh)
}
}
In this scheme you'll call player.update on every frame, giving it the time elapsed from the last frame. Note that the velocity is calculated from the second of the kinematic equations:
Which you should definitely know about.
427 - 360 = 67
so, your object need to jump by 67 points.
but, you need gravity and verticalspeed variables of course
so, you've to tell what is the value of your gravity variable