Is there a way to generate a 3D triangular curve using a cubic-bezier function connecting 3D points in Three.js?

After exploring this discussion, I am attempting to create a 3D curved triangle using a NURBS surface, but I'm struggling with setting up my 3D points for this task.

Here is my current implementation:

var edges = this.getEdges(), // An edge is comprised of a line connecting 4 dots in a bezier curve.
    dots = self.getDotsFromEdges(edges), // Collecting all dots in sequential order for surface construction.
...

nurbs = new THREE.NURBSSurface(deg1, deg2, knots1, knots2, ctrlPoints) ;

this.mesh.geometry.dispose() ;
this.mesh.geometry = new THREE.ParametricBufferGeometry(function(u, v, target) {
    return nurbs.getPoint(u, v, target) ;
}, 10, 10) ;

And here is the resulting output:

https://i.sstatic.net/LhCul.png

I have experimented with various settings but have not found any that work effectively.

Note: The white points represent the ends of the edges; The red points indicate the middle points of the bezier curve.
Note 2: dots[0] corresponds to point 0 in the provided image, and so forth.

Here is a working code snippet (also available as a fiddle version here)

...

Answer №1

If you want to create a Bezier Triangle, the following snippet contains the algorithm stored in the Geometry class. You can specify the number of triangles on one side of the triangle using the constructor. The code separates the algorithm and calculations (Geometry class) from the drawing code (Draw class).

To create a Bezier triangle, you need 10 control points (9 for edges and one for the "plane") as shown in the image below:

https://i.sstatic.net/mJ346.png

In this code, normals are not used, and the names of b points have been changed to p (e.g., b003 becomes p003). The formula used is based on cubic Bezier triangles with n=3:

https://i.sstatic.net/YnzGi.png

Where p_ijk represents a control point (for n=3, the sum above consists of 10 elements, hence we have 10 control points), and where B^n_ijk(r,s,t) are Bernstein polynomials defined for i,j,k>=0 and i+j+k=n.

https://i.sstatic.net/8S0Oo.png

or 0 otherwise. The domain of r,s,t in barycentric coordinates (where r,s,t are real numbers from [0, 1] and r+s+t=1) looks like this:

https://i.sstatic.net/puZbk.png

The regular positions for the black dots in the domain are calculated in the method barycentricCoords(n), and the definition of which point creates which triangles is done in the method genTrianglesIndexes(n) in the Geometry class. However, you have the flexibility to change these points' positions and density within the triangle to achieve different surface-triangle divisions. A snippet showing the domain in 2D is provided below.

Your final snippet includes a 3D cubic bezier triangle. The algorithm for this starts in the method

genTrianglesForCubicBezierTriangle(n, controlPoints)
within the Geometry class. Please note that after the first run in SO snippets, you may not see lines; reloading the page and running it again should display the triangles-lines.

Fiddle version available here.

Answer №2

I have made some modifications to the code originally created by Kamil Kiełczewski and split it into two distinct classes:

  1. BarycentricBufferGeometry, which is based on ParametricBufferGeometry
  2. BezierTriangle, derived from NURBSSurface

The updated version now behaves similarly to NURBSSurface.js but with improved efficiency.

Here is BarycentricBufferGeometry.js:

(code block for BarycentricBufferGeometry)

And here is BezierTriangle.js:

(code block for BezierTriangle)

You can see an example implementation below:

(example code block)

Answer №3

The utilization of the NURBSSurface function within your code, sourced from the NURBSSurface.js file, relies on the NURBSUtils.calcSurfacePoint function found in NURBSUtils.js. However, it's important to note that the calcSurfacePoint calculates points specifically for standard NUBRB surfaces where parameters are based on a rectangle (u,v) as outlined in this wiki.

To generate a "3D cubic bezier triangle", an alternate approach is required - one that involves developing custom code utilizing bezier-triangle formulas using input parameters representing triangle points within a Barycentric_coordinate_system.

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

Could the Redux store be used to access the state related to specific review comments?

I have a react class component that includes state variables. class NewComponent extends Component { state = { modalIsOpen: false, aa: true, bb: false, cc: false, dd: false, ee: 1, dd: [], cc: [], ff: [], gg: [], ...

What steps can be taken to resolve the issue of the Cannot POST /index.html error?

Here is an example of a calculator app created using HTML and Javascript. Upon running the program with nodemon and accessing localhost:3000, pressing the submit button triggers an error on Google Chrome. [nodemon] starting `node calculator.js` Server sta ...

Create interactive highcharts graphs using data from a CSV file generated through PHP

I'm having trouble working with Highcharts and csv data. Take a look at this example: http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/line-ajax/ $.getJSON('http://www.highcharts.com/ ...

Error encountered during navigation: navigator has not been defined

I encountered an issue where the page gets redirected upon form submission without triggering the catch block. However, in the backend, I am facing an error stating that the API body is not being executed. Below is the code snippet of the page: "use cl ...

Error message: npm command not recognized while running commands within an Electron application

While developing an electron app, I utilize shell commands with child_process.exec. One of the commands I use is npm run start, which functions perfectly in a development environment. However, upon building the application for production, all npm commands ...

Shadows and reflections are not supported on Threejs PlaneGeometry

I'm relatively new to the world of 3D graphics and three.js, and I'm struggling to figure out how to achieve individually illuminated polygons on a PlaneGeometry. I've been working on applying some noise to the vertices' z-values in ord ...

Testing ng-content in Angular 2

Is there a way to test the functionality of ng-content without the need to create a host element? For instance, let's say we have an alert component - @Component({ selector: 'app-alert', template: ` <div> <ng-conten ...

A child component in Vue.js unexpectedly starts updating when the parent component renders and uses object literals as props

I'm currently facing an issue with my Vue components where object literals are passed as props like: <child :prop1="{ foo: 'bar' }"></child> After rerendering the parent component, the prop prop1 changes and triggers an update ...

A timer created using jQuery and JavaScript

Looking for a way to automatically transition between three div elements with a fade in/out effect every 8 seconds? Check out this simple code snippet I wrote: $(".link1").click(function () { $(".feature1").fadeIn(1000); $(".feature2").fadeOut(1000) ...

Exploring Karma and Jasmine for Testing Angular Controllers Module

In an attempt to test my application, I have each controller defined in its own module rather than as a controller of the main app module, and then loaded as a dependency of the main app module. While running a test to check if the loginController is defin ...

Adding event listeners to modal buttons in a Handlebars template is a simple process that involves utilizing the `

I've been working on developing a web application that interacts with a news API to display articles. Each article is presented in a card format, and I have also incorporated modals using handlebars. My goal is for each card's button to trigger ...

The camera in Three.js First Person Controls is in constant motion

Currently, the game I am working on necessitates a first person controller and fortunately Three.js provides that functionality. However, I am facing an issue where the camera keeps flying around uncontrollably. The problem seems to be related to mouse mov ...

A proposal for implementing constructor parameter properties in ECMAScript

TypeScript provides a convenient syntax for constructor parameter properties, allowing you to write code like this: constructor(a, public b, private _c) {} This is essentially shorthand for the following code: constructor(a, b, _c) { this.b = b; thi ...

Using Typescript to set a custom timeout duration based on a dynamic variable within a for loop

My function includes a timeout that changes every 3 seconds: setActiveImage(promotions) { for (let i = 0; i <= promotions.length - 1; i++) { setTimeout(()=> { this.activeImage = 'http://myrul/public/Commercials/' + promo ...

Tips on preventing the need for null or undefined checks in JS/Typescript singletons that have an initialization function

Is there a way to streamline the process of handling props in an Object literal that is dynamically initialized only once? I'm looking for a pattern that would eliminate the need for repetitive null/undefined checks and throw errors when certain metho ...

Exploring JSON Data with NativeScript

As a newcomer to NativeScript and JSON, I am currently facing challenges in accessing data from my JSON file. My main goal right now is to simply log some of the data for debugging purposes. Below is the code snippet from my view-model: var config = requ ...

Utilizing CSS to Display a Variety of Colors within a Text String

Is it possible to style different words in a sentence with various colors using only CSS, without using the span element? For instance, how can I make the word "Red" appear in red, "Blue" in blue, and "Green" in green within an h1 tag? ...

Efforts to render a texture do not result in any errors, yet the texture fails to appear on the

After creating a model with a background sky and ground surface, I attempted to add texture to the surface but encountered a problem where the surface was not displaying any textures. Upon further investigation, I suspect that the scene is being rendered ...

In the XHTML mode, MathOverflow's invaluable mathematical expertise shines brightly

I am interested in incorporating the unique “piece of valuable flair™” from MathOverflow onto my website. The issue I am facing is that I want my webpage to comply with XHTML5 standards, meaning it should be served with the MIME type application/xht ...

Determine the Ratio by comparing shared keys within an array of dictionaries

Looking to create a function that can calculate ratios based on specific keys and control which keys are eligible for ratio calculation. num = [{"HCOName":8919,"timestamp":"2019-01-01T00:00:00.000Z","Territory":"USA"}, {"HCOName":8275,"timestamp":" ...