What is the best way to separate an ellipse into evenly sized portions?

This function is used to determine the coordinates of a vertex on an ellipse:

function calculateEllipse(a, b, angle) 
{
    var alpha = angle * (Math.PI / 180) ;
    var sinalpha = Math.sin(alpha);
    var cosalpha = Math.cos(alpha);

    var X = a * cosalpha - b * sinalpha;
    var Y = a * cosalpha + b * sinalpha;
}

Is there a way to calculate the "angle" in order to achieve equal or approximately equal circumference segments?

Answer №1

Based on the information shared by Jozi in the original poster's comments, the challenge at hand is not how to divide an ellipse into equal segments (which would involve complicated integrals), but rather to create an ellipse using line segments of approximately equal length.

Several methods are available for achieving this, with the concentric circle approach known as 'the draftman's method' being particularly suitable for the task. An interactive demonstration of this method can be found here, which requires installation of the Mathematica player.

However, it's worth noting that approaches like these may only produce roughly equal segment lengths when dealing with low eccentricities. Extreme eccentricities introduce greater complexity. One simple solution involves linearly approximating the length of a line segment within each quadrant and then precisely determining the positions of the endpoints in that quadrant.

Visualizing an ellipse quadrant with parameters a = 5, b = 1:

A plot showcasing the arc length corresponding to an infinitesimal angle change is shown below:

The x axis represents angles in radians, while the y axis displays arc lengths resulting from a 1 radian angle change. The formula used here, derived from equations in the linked Wikipedia article, is

y = Sqrt(a^2 Sin^2(x) + b^2 Cos^2(x))
. Crucially, the integral of this function - the area under the curve - equals the total length of the arc in the entire quadrant.

An approximation using a straight line is depicted here:

This line has a gradient of m = (a-b) / (Pi/2) and intersects the y axis at c = b. By geometry analysis, we find the area under the red curve to be A = (a+b)*Pi/4.

By leveraging this understanding and associating area under the curve with the total curve length, constructing an elliptical approximation boils down to finding a midpoint-rule quadrature of the red line such that each rectangle has equal area.

Translating this concept into an equation, representing a rectangle's position in a quadrature with its left-hand boundary x and width w, leads us to:

(v*m)*w^2 + (m*x+c)*w - A/k == 0

In this equation, k denotes the number of parts used to approximate the quadrant, and v signifies a weighting function. Through iterative processes involving setting values like x0 = 0 and solving for subsequent boundaries, the quadrature construction progresses until reaching the final boundary point Pi/2.

The weighting function v dictates where rectangles intersect the red line. A constant value of 0.5 corresponds to midpoint crossings, generating 10 points as seen below:

Varying v within the range [0, 1]k/2

Answer №2

Since this information is too lengthy for a comment, I believe it qualifies as an answer...

Here's a straightforward mathematical approach to creating a rough estimation. Begin by selecting one quadrant. By reflecting in the X and Y axis, you can derive the data for the remaining quadrants. Compute (x,y) for angles = 0 degrees, 1 degree, ... up to 90 degrees. Next, determine the short distances between consecutive points. If (x_n, y_n) represent the coordinates at angle = n, then the distance D between points (x_n, y_n) and (x_n+1, y_n+1) can be calculated using Pythagoras theorem: D = sqrt((x_n+1 - x_n)^2 + (y_n+1 - y_n)^2). Utilize this formula to generate a table of cumulative distances along the ellipse for angles ranging from 0 degrees to 90 degrees. This essentially provides the inverse function you are seeking. You're not limited to a step size of 1 degree; any angle that evenly divides 90 degrees could be used.

To determine the angle corresponding to a perimeter step size of x, locate the largest angle n in your table where the partial perimeter is less than or equal to x. The partial perimeter of angle n+1 will exceed x. Employ linear interpolation to ascertain the fractional angle associated with x.

This method involves approximating the ellipse with straight line segments and substituting them for the original curve; essentially a first-order approximation. For improved accuracy, consider employing Simpson's rule or a similar technique instead of linear interpolation.

Indeed, you must calculate the table beforehand. However, once the table is prepared, the subsequent calculations are straightforward. For tasks that do not necessitate high precision, this process is fairly simple both mathematically and from a coding perspective.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Trigger the ASP .NET OnCheckedChange server event using JavaScript

One issue I encountered is related to a checkbox with an OnCheckedChanged event. Occasionally, I modify the checked status of the checkbox using javascript. However, when this occurs, the OnCheckedChanged event does not trigger. Is there any method to ens ...

Utilize pg-promise for inserting data with customized formatting using the placeholders :name and :

After reviewing the pg-promise documentation, I came across this code snippet: const obj = { one: 1, two: 2 }; db.query('INSERT INTO table(${this:name}) VALUES(${this:csv})', obj); //=> INSERT INTO table("one"," ...

Attempting to retrieve an element by its ID from a div that was dynamically loaded using AJAX

I am having trouble retrieving the value of an element with getElementById from a div that is loaded via ajax. Let me explain: In 'example.php' I have the following JavaScript code: <script type= "text/javascript"> var page=document.getE ...

Enzyme in Action: Using React.js to Emulate a Click Event

I have been working on a React.js application which is a straightforward Cart app. You can take a look at the code sandbox here: https://codesandbox.io/s/znvk4p70xl The issue I'm facing is with unit testing the state of the application using Jest and ...

Anomaly in the default checked state of checkboxes

I'm currently working on a project and encountering an issue with the code below. I need to incorporate a forEach() loop within getElements() instead of using map(). Additionally, I want the default state of a checkbox to remain checked even after nav ...

The spacing issue in jQuery autocomplete is causing the results to not display properly within the modal

My webpage serves as a basic school student/class manager. Currently, I have two search bars that trigger different API calls, both returning a List. However, the issue arises when displaying the results as they have spaces between them. Another problem I ...

The computer system encountered an issue in computing the values of the text

Possible Duplicate: Unable to get textfield value using jQuery My current project involves updating input fields based on user changes in quantity for items. Each item is retrieved from a database and I am generating invoices for customers. However, ...

The order of the LinkedHashMap returned from the server is not maintained in the AJAX response

I have implemented a LinkedHashMap to store map entries sorted by a specific business rule, and then sending it to the client. However, I am facing an issue where my AJAX response is always sorted by the map key instead of the business rule. Here is the c ...

Can the 'Water Shader Animation' be altered to have a non-spherical shape?

http://codepen.io/Khangeldy/pen/gPJoxJ JS // setting up camera, scene, and renderer var scene, camera, renderer; scene = new THREE.Scene(); var fov = 75, aspect = window.innerWidth / window.innerHeight; camera = new THREE.PerspectiveCamera(fov, a ...

What could be causing the issue of the title in req.body to display as 'undefined'?

I am currently learning about NODE JS and practicing working with POST forms from PUG to a NODE JS server. I am facing an issue where the submission input is coming back as 'undefined' when I submit a form from the web browser. In the code snipp ...

Implementing Jquery tabs into the code causes the vertical auto-scroll to smoothly glide beyond anchor points

I recently implemented a smooth autoscroll feature on my webpage using the CSS-Tricks code found here: http://css-tricks.com/snippets/jquery/smooth-scrolling/ Everything was working perfectly until I added jQuery tabs to display some of the content. Now, ...

Adding data and consolidating MongoDB records

I'm currently immersed in working with mongoose ODM and MongoDB. I've encountered a minor hiccup that I can't quite figure out. In my User collection, I have the following schema: const userSchema = new Schema({ name: String, posts: [{type ...

Retrieving information from a GET request/JSON payload

It's been a while since I last worked with JavaScript and I'm struggling to figure out how to extract data from a JSON object. Currently, I am making a simple GET request to the Giphy API in order to retrieve URLs from the response, but for some ...

creating dynamic navigation tabs with scroll functionality

Utilizing Bootstrap Nav Tabs and Tab panes on my website has been a smooth process. However, I am encountering some difficulty in adding extra links that not only activate the Tab Panes but also scroll to them. The issue seems to be related to a specific l ...

Changing variables within anonymous functions in javascript can be done by using the parameters passed into

Hello everyone, I'm currently working on a new JavaScript project and I've encountered an issue. I need to figure out how to change variables in anonymous functions. Can anyone help me with this? updateName : function(){ var firstNa ...

Is there a way to prevent elements on a web page from shifting when the page width becomes narrow enough?

Currently, as I delve into the world of web development with Svelte, I am in the process of creating a basic website to put my knowledge to the test. The main aim is to ensure that no matter how much the page is resized, the text and video content remain e ...

Encountering a problem when trying to set the value in the controller and receiving unexpected output from the console

Attempting to assign a value to an object and show it in the view, but encountering an issue. When setting the vm.order.info.when to 'Any Value' and logging the vm.order.info, the value appears correct at first glance. However, upon inspecting th ...

What is the best way to adjust the CSS of an element within the #shadow-root (open) in web development?

When dealing with a "#shadow-root (open)" element, it appears that manipulating the style using only CSS is not feasible. The shadow-root was generated by a third-party JavaScript script and displays an element as an overlay on the page that I am trying to ...

Implementing Ajax calls to dynamically update Datatable results

Currently integrating Datatables.js with an ajax call for data retrieval. The json response I'm receiving is as follows: "success":true,"message":"","items":[{"id":"1","ip_address":"127.0.0.1","email... My data is stored within the data.items array ...

Unable to assign values to object variables in JavaScript

I'm currently working on a project in AngularJS that involves reading data from files. The goal is to assign the content to a variable within an object if the file is read successfully, otherwise, assign "NA" to the same variable. function customer($ ...