JavaScript Function to get point on line where two points are known function point line of code,point function line,function point

Given two points:

const point1 = {x: 100, y: 0.95}
const point2 = {x: 75, y: 1.05}

I need to know the value of y when x equals some arbitrary value.

Please assume a linear relationship exists.

For example, what is y when x is 80? what is y when x is 70?

Is there a function that I could use for this?

Currently I've been confused by mathematical explanations and would ideally like a JavaScript or jQuery function that, when given an arbitrary x value returns the y value.

Answer:1

Sure, the gradient of a line is the amount y increases for every unit x increases. E.g. if y goes up 5 for every 2 x goes up, the line is said to have a gradient of 2.5.

The gradient can be calculated from 2 points like so:

var gradient = (point2.y - point1.y) / (point2.x - point1.x);

The intercept of a line is the y value it crosses the y axis at. It can be calculated from 1 point like so:

var intercept = point1.y - (gradient * point1.x);

The y value for any x value can then be calculated:

var x = 10;
var y = gradient * x + intercept;

A function which combines these things might look like:

function yFromX(point1, point2, x) {
  var gradient = (point2.y - point1.y) / (point2.x - point1.x);
  var intercept = point1.y - (gradient * point1.x);
  return gradient * x + intercept;
}
Answer:2
const point1 = {x: 100, y: 0.95}
const point2 = {x: 75, y: 1.05}

function getY (x) {
    var gradient = (point1.y - point2.y)/(point1.x - point2.x);
    return point1.y + gradient * (x - point1.x);
}

alert(getY(90));
Answer:3

I am trying to get an input box to be disabled when a checkbox is checked. I'm trying to use Knockoutjs to get this done, but it doesn't seem to work. Here is my html: <input id="input1" type="...

I am trying to get an input box to be disabled when a checkbox is checked. I'm trying to use Knockoutjs to get this done, but it doesn't seem to work. Here is my html: <input id="input1" type="...

  1. knockout js disabled binding
  2. knockout js disable binding

I'm trying to send characters to an input element based on user actions. I'm trying to use KeyboardEvent with dispatchEvent but whatever I do, it doesn't work For example: let keyEvent = new ...

I'm trying to send characters to an input element based on user actions. I'm trying to use KeyboardEvent with dispatchEvent but whatever I do, it doesn't work For example: let keyEvent = new ...

I want to find all word which start with mc and followed by all digits only var myString="hi mc1001 hello mc1002 mc1003 mc1004 mc mca" Require output = [ mc1001,mc1002,mc1003,mc1004] My solution: ...

I want to find all word which start with mc and followed by all digits only var myString="hi mc1001 hello mc1002 mc1003 mc1004 mc mca" Require output = [ mc1001,mc1002,mc1003,mc1004] My solution: ...

  1. find word start with
  2. how to find word startup folder
  3. word finder start with u
  4. find word start with st
  5. find word start with sc
  6. find word start with gl
  7. find word start with sh
  8. find word start with air
  9. find word start with cou
  10. find word start with bri
  11. find word start with qua
  12. find word starting with regex
  13. find word starting with python
  14. find word starting with x
  15. find word starting with hash
  16. find word starting with k
  17. find word starting with play
  18. word find start of line
  19. word finder start with c
  20. word finder start with v

I have created a custom css tooltip, however the tooltip width is very narrow (only 1-2 words per line). Fiddle example of the problem I would like the tooltip size to be dynamically generated, as ...

I have created a custom css tooltip, however the tooltip width is very narrow (only 1-2 words per line). Fiddle example of the problem I would like the tooltip size to be dynamically generated, as ...