- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to generate array of n equidistant points along a line segment of length x with JavaScript?
To generate array of n equidistant points along a line segment of length x, use the below syntax −
for (var anyVariableName= 0; yourVariableName< yourStartPointName; yourVariableName++) { var v = (yourVariableName+1)/ (yourStartPointName+1); var v2 = v*yourEndPointName;
Example
function drawPoints(start, end) { const arrayOfPoints = [] for (var index = 0; index < start; index++) { var v = (index+1)/ (start+1); var v2 = v*end; arrayOfPoints.push(Math.round(v2)); } return arrayOfPoints; } const arrayOfPoints = drawPoints(5, 50); console.log("The Points="); console.log(arrayOfPoints);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo53.js
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo54.js The Points= [ 8, 17, 25, 33, 42 ]
- Related Articles
- Construct a line segment Ab of length 8cm. From this, cut a line segment AC of length 3.6 cm. Measure the remaining line segment
- Draw a line segment $AB$ of length $5.8 cm$. Draw the perpendicular bisector of this line segment.
- JavaScript function to take a number n and generate an array with first n prime numbers
- Generate a Vandermonde matrix of given degree with float array of points in Python
- Generate a Vandermonde matrix of given degree with complex array of points in Python
- $AB$ is a line segment $P$ and $Q$ are points on opposite sides of $AB$ such that each of them is equidistant from the points $A$ and $B$. Show that the line $PQ$ is perpendicular bisector of $AB$."
- Draw a line segment $AB$ and by ruler and compasses, obtain a line segment of length $frac{3}{4}(AB)$.
- Average of each n-length consecutive segment in a Python list
- Draw a line segment of length ( 7.3 mathrm{~cm} ) using a ruler.
- Draw a line segment $AB$ and bisect it. Bisect one of the equal parts to obtain a line segment of length $frac{1}{2}(AB)$.
- Generate a Pseudo Vandermonde matrix of the Laguerre polynomial and x, y array of points in Python
- Generate a Pseudo Vandermonde matrix of the Legendre polynomial and x, y array of points in Python
- Generate a Vandermonde matrix of the Chebyshev polynomial with float array of points in Python
- Generate a Vandermonde matrix of the Chebyshev polynomial with complex array of points in Python
- Generate a Vandermonde matrix of the Laguerre polynomial with float array of points in Python

Advertisements