Looking for someone that's good at math to figure something out for me. 5k robux?

I haven’t had luck in finding someone that knows/is interested in writing a bit of math-heavy script for me, so I’ll try here:

I’m trying to make a script that connects the two red points with x number of line segments where each line segment is an identical length. The angle of the line segments should be identical, so it’s basically generating the fastest and smoothest arc possible between two points with x amount of line segments of y size each. 2D

Anyone interested? Message me first before starting on here or discord: BrokenBone#1341 . Will pay 5k robux if it works properly(ie doesnt have errors or bruteforce calculations)

If each segment has to be identical length and angle, you don’t necessarily generate the “smoothest arc” possible in all situations. Are you sure you don’t just want to connect the points with a cubic Bézier?

I don’t know much about math. Someone else suggested bezier but I can’t apply it myself.

I would like the arc to be as smooth as possible, I’m sure there is a formula that can be crafted for that

Emptybaseplate.rbxl (13.6 KB)

Think of it as points on a circle. Both start and end-point lies on a circle. Start is where we start to draw our circle, then the endpoint is drawn a ‘percentage of a full circle’ away from start.
See the image illustration.
Namnlös
Left: Red starts 0% away from start, Right: Red starts 50% away from start.
Left: Split into 4 edges, Right split into 2 edges.

Once you got these two points you can split the path inbetween into any number of points (blue circles in the image) and get exactly same distance between each point.
This is super wierdly explained ik but I hope the demo will help more.

I actually thought of that before, I just know of no way of implementing that. I never paid attention in math class.

1 Like

I can do it

In order to do this from a circular approach (where all interior angles are equal), you need another piece of information, such as a third point (the center of the circle you want to fit) or the arc length of the path you want to make.

Modular solution which lets you use any parametric path, and works on Vector2s or Vector3s so it works regardless of whether you’re planning on using it for something 3D or 2D. I provide a cubic bezier path as the one used in the example, but you could plug any other parametric path too.

In the example a path is drawn starting through part A’s position / direction and ending at part B’s position / direction, divided into the number of segments set in ExampleScript under Workspace.

Details: This just estimates the length of the parametric function provided for the path in 3x as many divisions as the number of segments that you ask for in order do divide it into equal length sections, which should provide a low error / reasonable result for all but the most pathological cases.

3 Likes

Thanks, but I don’t think that’s quite what I need. The script is taking into account the way the A/B parts are facing, when it doesn’t matter for what I’m doing, and I dunno how to take the existing code and bend it to what I want done.

I’m no math expert, but I got an idea for this.

So what your’e trying to do is make a semi circle with a diameter and b segments. So what you can do is connect the point P and point R with a non-visible line of c length. You would then draw a line from the middle of that line to extend out to have a length of a. Go with an even number of lines. So what you do after that is somehow figure out a way to generate h/2 segments on each side where the first point connects the last ones end point and the new end point is the same height but is higher in the current orientation by 0.1a to the power of the number segment it is from the current side to the power.
@Oseday
Hopefully somebody can transform this into lua. Ill come back later when Im free and try to make this better. :wink:

I’m not entirely sure, but I can imagine that OP also wants situations like these to be solvable:

image

In which case an approach where you fit a spherical sector on the gap won’t work out

Nope, I just want a perfectly smooth curve that perfectly houses x amount of line segments of y length. There are only two possible curves that could fit two points like that, a curve forward or a curve backward. No fancy squiggles necessary.

1 Like

Oh, you should have mentioned that, then it should just become a quadratic Bézier:

image

You extend the lines and find the intersection of them, call that B, then you form a quadratic Bézier with A,B,C as control points. Let me see if I have some example code lying around.

1 Like

You couldn’t have worded it better! :grinning:

BezierTest.rbxl (14.3 KB)

If you press play and move the parts / control point around, you can see it form a smooth curve of approximately same length segments (edit: about ~1% difference? depends on accuracy of discretization), in about 1/1000 of a second (on my setup, at least). The relevant code is in ServerScriptService.

image

You want to have the control point on the intersection between the two lines that the parts would form.

So all that’s left to do is to determine the position of the red part programmatically, but I don’t have enough time to figure out a formula for that right now. Maybe consider posting a thread in Scripting Support about finding an intersection between 2 lines in 2D defined by a point and bearing each.

1 Like

If you or someone could use it, I made a Bezier Curves module sometime ago with interpolation function and full documentation.

Bezier curves aren’t applicable to the problem. They can’t represent a circle, and the constraint that the angle between each line segment and the next is constant means that the solution lies on a circular arc. Arc length of Bezier curves is also a lot more complicated than circular arcs, so Bezier approximations to circles don’t simplify anything.

@PlaceRebuilder has the right idea. Think of the line segment that connects the two red points as the chord of the circle that passes through both points. There are infinitely many such circles, but for a given number of segments of specific length, there will be just two circles that contain all the segment endpoints. Your discrete solution is going to be a partial regular n-gon that is inscribed in one of these circles.

1 Like

It’s difficult to tell what OP really wants because he didn’t describe his use case, just a specific solution (“smoothest possible, fixed segment length, fixed angle”). Maybe he actually just needs “smoothest possible arc” rather than “fixed angle”. I did see him mention in Discord that he’d be okay with my solution and letting the user determine the position of control point, so this could indicate that he’d prefer a curve with a control point over fitting a circular/oval arc on the gap.

Also, keep in mind, fitting a circular arc doesn’t always work, you sometimes need to stretch it to make an oval-like arc, such as when this happens:

image

Okay, so then we normalize the coordinate system so that it fits a circular arc, and then transform that back to get the oval-like arc. But then note, we also need to take into account that OP wants “fixed segment lengths”, so when we determine the segments, we need to keep our malformed coordinate system into account… doesn’t seem too trivial to me to calculate this, at least.

(But would love to know if it’s easier than I think it is)

1 Like

Away from pc, Ill post a pic in a bit. But the rotation of the two points dont matter at all. Dont think of it as connecting two lines with a curve, think of it as connecting two random individual points with a perfect curve.

It sound like the problem he is trying to solve doesn’t care about the direction of the start and end point, so for example a solution to the curve you posted with x = 2 would be something like this:
https://gyazo.com/bd9d29980ebe5918aed27007c7a0b8d2.png