Mark Bufton Posted November 24, 2017 Share Posted November 24, 2017 Hi guys, Rather a technical question I'm afraid and one that I do have a functional solution to, but wanted to take the opportunity to learn something new. I'm attempting to create the deck of a ship (the Titanic) from blueprints, using a curve3 object to create the outline of the decks (eventually using it to create path points for a polygon mesh/extruded shape, but simply used as line paths for the time being). This works perfectly fine, of course, as the deck plans are completely flat - using the X and Z co-ordinates (in my case) of the curve3 I can match the outline of the decks with reasonable precision. A ship, however, doesn't tend to have flat decks - Titanic being no exception. The decks are curved upwards both forward and aft. One (almost) solution being to create an additional curve depicting the deck on a side (profile) blueprint (containing the same number of points as the aforementioned deck outline). I have written functions to extract the x, y and z points of any given curve3 path, and could pass the x and z data from the deck curve, and the y data from the side profile curve, as arguments to my own custom curve. This would work in theory, if both curves were identical - then the x co-ordinates of the side profile would match perfectly the x co-ordinates of the deck plan's curve. Where the poop deck, for instance, curves around sharply at the stern, the x co-ordinates of the deck outline will get considerably closer together, whereas they won't do so on the deck profile - using my 'solution' would likely result in a very warped deck. My solution to the problem is a simple one - simply line up the two plans and visually adjust the y input of the start, end and control points of the bezier curve function (depicting the deck outline) to incorporate the curve of the deck - which is gentle enough to achieve easily. My curious nature tends to get the better of me, as you all probably know, and leads me to ponder if there is a way to programatically get the x, y or z co-ordinates at any given point of the curve3? Take a simple curve from vector3(10,0,-10) to vector3(50,0,0) - if, for example, I wanted to know the value of z at x:31.265, am I able to get that or calculate that programatically without being a mathematical genius or including a massive number of points and searching the path array for the nearest value? Quote Link to comment Share on other sites More sharing options...
jerome Posted November 24, 2017 Share Posted November 24, 2017 http://doc.babylonjs.com/how_to/how_to_use_curve3 Unfortunately, there's no way to get a value from a curve at some distance or a given x value. Why ? because, despite it's called a "curve", it's actually a series of points (Vector3) linked by straight linear segments. All these tiny segments rendered together are an approximation of the real mathematical curve. So given some x value, you could maybe get the nearest surrounding points V1, V2 and interpolate the right y on the line V1V2. Mark Bufton 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted November 25, 2017 Share Posted November 25, 2017 The following PG uses the start, end and two control points needed by Curve3 to draw a cubic Bezier Curve to produce a function that returns any point on the curve given the fractional distance (t) along the curve. https://www.babylonjs-playground.com/#CCTRHM Hope it helps jerome and Mark Bufton 1 1 Quote Link to comment Share on other sites More sharing options...
Mark Bufton Posted November 25, 2017 Author Share Posted November 25, 2017 Lovely. Thanks guys!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.