Creating Weighted Bezier Curves
Weighted Bezier curves give you precise control over how strongly each control point influences the curve's shape. Think of weights as invisible magnets attached to each control point - the heavier the weight, the more the curve gets pulled toward that point.
This example demonstrates the dramatic effect weights can have on curve shape. We start with five control points arranged in 3D space, then assign different weight values to each point. The middle control point receives the heaviest weight of 200, while the others get lighter weights ranging from 10 to 60.
The visual result shows three key elements that help you understand how weights work. The bright yellow curve represents the final weighted Bezier shape, dramatically pulled toward the middle point due to its high weight. A thin white polyline connects all the control points in order, showing you the basic path without any curve smoothing. Green spheres appear at each control point, with their sizes corresponding to the weight values - the larger the sphere, the stronger that point's influence on the curve.
Understanding the Weight Effect
When you run this example, you'll see how the curve bends strongly toward the middle control point. This happens because its weight of 200 is much higher than the surrounding points. The curve still passes through the general area of all control points, but it gets pulled most strongly toward the heavily weighted middle point, creating a distinctive bulge in that direction.
This technique is invaluable for design work where you need the curve to emphasize certain areas while maintaining smooth transitions. Automotive designers use weighted Bezier curves to ensure body panels flow correctly through critical styling points, while maintaining smooth surfaces elsewhere.
- Rete
- Blockly
- TypeScript
{
"id": "rete-v2-json",
"nodes": {
"d93ff9312fbaba0d": {
"id": "d93ff9312fbaba0d",
"name": "bitbybit.occt.shapes.wire.createBezierWeights",
"customName": "bezier weights",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"closed": false
},
"inputs": {
"points": {
"connections": [
{
"node": "71dc37e5bf31abc7",
"output": "list",
"data": {}
}
]
},
"weights": {
"connections": [
{
"node": "5e78ae53129348d2",
"output": "result",
"data": {}
}
]
}
},
"position": [
1474.6086829856026,
340.89493244534634
]
},
"6c71764f860388cb": {
"id": "6c71764f860388cb",
"name": "bitbybit.point.pointXYZ",
"customName": "point xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": -10,
"y": 0,
"z": 0
},
"inputs": {},
"position": [
233.46875,
142.23828125
]
},
"262c5b4158e10e7f": {
"id": "262c5b4158e10e7f",
"name": "bitbybit.point.pointXYZ",
"customName": "point xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": -5,
"y": 0,
"z": 3
},
"inputs": {},
"position": [
224.73046875,
479.984375
]
},
"aef87dde79aae140": {
"id": "aef87dde79aae140",
"name": "bitbybit.point.pointXYZ",
"customName": "point xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 0,
"y": 7,
"z": -5
},
"inputs": {},
"position": [
224.74154154459637,
833.5904947916667
]
},
"6eb81a9d83fbbfe7": {
"id": "6eb81a9d83fbbfe7",
"name": "bitbybit.point.pointXYZ",
"customName": "point xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 5,
"y": 0,
"z": 3
},
"inputs": {},
"position": [
242.77880556002404,
1187.0961686117394
]
},
"8f6ffca91f2b1d12": {
"id": "8f6ffca91f2b1d12",
"name": "bitbybit.point.pointXYZ",
"customName": "point xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 10,
"y": 0,
"z": 0
},
"inputs": {},
"position": [
255.1210077869103,
1528.317664158235
]
},
"71dc37e5bf31abc7": {
"id": "71dc37e5bf31abc7",
"name": "bitbybit.lists.createList",
"customName": "create list",
"data": {},
"inputs": {
"listElements": {
"connections": [
{
"node": "6c71764f860388cb",
"output": "result",
"data": {}
},
{
"node": "262c5b4158e10e7f",
"output": "result",
"data": {}
},
{
"node": "aef87dde79aae140",
"output": "result",
"data": {}
},
{
"node": "6eb81a9d83fbbfe7",
"output": "result",
"data": {}
},
{
"node": "8f6ffca91f2b1d12",
"output": "result",
"data": {}
}
]
}
},
"position": [
809.4944869050374,
791.4060121932632
]
},
"5e78ae53129348d2": {
"id": "5e78ae53129348d2",
"name": "bitbybit.json.parse",
"customName": "parse",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"text": "[10,60,200,30,10]"
},
"inputs": {},
"position": [
820.9003613826357,
1045.8565882239327
]
},
"1badef86dffd3d2b": {
"id": "1badef86dffd3d2b",
"name": "bitbybit.vector.max",
"customName": "max",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"vector": {
"connections": [
{
"node": "5e78ae53129348d2",
"output": "result",
"data": {}
}
]
}
},
"position": [
1452.8517350042941,
1584.36307724802
]
},
"6628a0dad5393c00": {
"id": "6628a0dad5393c00",
"name": "bitbybit.vector.min",
"customName": "min",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"vector": {
"connections": [
{
"node": "5e78ae53129348d2",
"output": "result",
"data": {}
}
]
}
},
"position": [
1453.5379674005778,
1314.9458583914063
]
},
"708bd3fd447df194": {
"id": "708bd3fd447df194",
"name": "bitbybit.polyline.create",
"customName": "polyline",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"isClosed": false
},
"inputs": {
"points": {
"connections": [
{
"node": "71dc37e5bf31abc7",
"output": "list",
"data": {}
}
]
}
},
"position": [
1470.8643520387145,
15.655298073315691
]
},
"02f75fd91278ddf0": {
"id": "02f75fd91278ddf0",
"name": "bitbybit.math.remap",
"customName": "remap",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"number": 0.5,
"fromLow": 0,
"fromHigh": 1,
"toLow": 0.3,
"toHigh": 0.9
},
"inputs": {
"number": {
"connections": [
{
"node": "a1d8b49442cfbed2",
"output": "result",
"data": {}
}
]
},
"fromLow": {
"connections": [
{
"node": "6628a0dad5393c00",
"output": "result",
"data": {}
}
]
},
"fromHigh": {
"connections": [
{
"node": "1badef86dffd3d2b",
"output": "result",
"data": {}
}
]
}
},
"position": [
2340.141780945838,
1415.6477847941433
]
},
"a1d8b49442cfbed2": {
"id": "a1d8b49442cfbed2",
"name": "bitbybit.lists.flatten",
"customName": "flatten",
"data": {
"nrLevels": 1
},
"inputs": {
"list": {
"connections": [
{
"node": "5e78ae53129348d2",
"output": "result",
"data": {}
}
]
}
},
"position": [
1842.606441779354,
1082.6783355134344
]
},
"594b69638201ab5d": {
"id": "594b69638201ab5d",
"name": "bitbybit.occt.shapes.solid.createSphere",
"customName": "sphere",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": true,
"flatten": 0,
"forceExecution": false
},
"radius": 1,
"center": [
0,
0,
0
]
},
"inputs": {
"center": {
"connections": [
{
"node": "1acceaf1728a9bb6",
"output": "result",
"data": {}
}
]
},
"radius": {
"connections": [
{
"node": "02f75fd91278ddf0",
"output": "result",
"data": {}
}
]
}
},
"position": [
2802.6462312888184,
788.517960703051
]
},
"1acceaf1728a9bb6": {
"id": "1acceaf1728a9bb6",
"name": "bitbybit.lists.flatten",
"customName": "flatten",
"data": {
"nrLevels": 1
},
"inputs": {
"list": {
"connections": [
{
"node": "71dc37e5bf31abc7",
"output": "list",
"data": {}
}
]
}
},
"position": [
1844.9251455808178,
867.378536261973
]
},
"9e4757c9a3030d87": {
"id": "9e4757c9a3030d87",
"name": "bitbybit.draw.drawAnyAsync",
"customName": "draw any async",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"entity": {
"connections": [
{
"node": "594b69638201ab5d",
"output": "result",
"data": {}
}
]
},
"options": {
"connections": [
{
"node": "ffb4da8064c6349b",
"output": "result",
"data": {}
}
]
}
},
"position": [
3404.609864091567,
786.0901195986705
]
},
"ffb4da8064c6349b": {
"id": "ffb4da8064c6349b",
"name": "bitbybit.draw.optionsOcctShapeSimple",
"customName": "options occt shape simple",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"precision": 0.05,
"drawFaces": true,
"faceColour": "#37ff00",
"drawEdges": false,
"edgeColour": "#ffffff",
"edgeWidth": 2
},
"inputs": {},
"position": [
2813.0669683419205,
1228.3267499707356
]
},
"5d978b01fc903574": {
"id": "5d978b01fc903574",
"name": "bitbybit.draw.drawAnyAsync",
"customName": "draw any async",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"entity": {
"connections": [
{
"node": "d93ff9312fbaba0d",
"output": "result",
"data": {}
}
]
},
"options": {
"connections": [
{
"node": "8da0996b9ae76bc7",
"output": "result",
"data": {}
}
]
}
},
"position": [
2648.015406962442,
129.78266326628432
]
},
"8da0996b9ae76bc7": {
"id": "8da0996b9ae76bc7",
"name": "bitbybit.draw.optionsOcctShapeSimple",
"customName": "options occt shape simple",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"precision": 0.05,
"drawFaces": false,
"faceColour": "#000000",
"drawEdges": true,
"edgeColour": "#e4ff1a",
"edgeWidth": 10
},
"inputs": {},
"position": [
2249.0695731821565,
364.8567725172626
]
}
}
}
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="point1">point1</variable><variable id="point2">point2</variable><variable id="point3">point3</variable><variable id="point4">point4</variable><variable id="point5">point5</variable><variable id="pointsList">pointsList</variable><variable id="weights">weights</variable><variable id="bezierWire">bezierWire</variable><variable id="polylineRef">polylineRef</variable><variable id="minWeight">minWeight</variable><variable id="maxWeight">maxWeight</variable><variable id="spheres">spheres</variable><variable id="sphere1">sphere1</variable><variable id="sphere2">sphere2</variable><variable id="sphere3">sphere3</variable><variable id="sphere4">sphere4</variable><variable id="sphere5">sphere5</variable></variables><block type="variables_set" id="create_point1" x="50" y="50"><field name="VAR" id="point1">point1</field><value name="VALUE"><block type="bitbybit.point.pointXYZ" id="point1_coords"><value name="X"><block type="math_number" id="p1_x"><field name="NUM">-10</field></block></value><value name="Y"><block type="math_number" id="p1_y"><field name="NUM">0</field></block></value><value name="Z"><block type="math_number" id="p1_z"><field name="NUM">0</field></block></value></block></value><next><block type="variables_set" id="create_point2" x="50" y="150"><field name="VAR" id="point2">point2</field><value name="VALUE"><block type="bitbybit.point.pointXYZ" id="point2_coords"><value name="X"><block type="math_number" id="p2_x"><field name="NUM">-5</field></block></value><value name="Y"><block type="math_number" id="p2_y"><field name="NUM">0</field></block></value><value name="Z"><block type="math_number" id="p2_z"><field name="NUM">3</field></block></value></block></value><next><block type="variables_set" id="create_point3" x="50" y="250"><field name="VAR" id="point3">point3</field><value name="VALUE"><block type="bitbybit.point.pointXYZ" id="point3_coords"><value name="X"><block type="math_number" id="p3_x"><field name="NUM">0</field></block></value><value name="Y"><block type="math_number" id="p3_y"><field name="NUM">7</field></block></value><value name="Z"><block type="math_number" id="p3_z"><field name="NUM">-5</field></block></value></block></value><next><block type="variables_set" id="create_point4" x="50" y="350"><field name="VAR" id="point4">point4</field><value name="VALUE"><block type="bitbybit.point.pointXYZ" id="point4_coords"><value name="X"><block type="math_number" id="p4_x"><field name="NUM">5</field></block></value><value name="Y"><block type="math_number" id="p4_y"><field name="NUM">0</field></block></value><value name="Z"><block type="math_number" id="p4_z"><field name="NUM">3</field></block></value></block></value><next><block type="variables_set" id="create_point5" x="50" y="450"><field name="VAR" id="point5">point5</field><value name="VALUE"><block type="bitbybit.point.pointXYZ" id="point5_coords"><value name="X"><block type="math_number" id="p5_x"><field name="NUM">10</field></block></value><value name="Y"><block type="math_number" id="p5_y"><field name="NUM">0</field></block></value><value name="Z"><block type="math_number" id="p5_z"><field name="NUM">0</field></block></value></block></value><next><block type="variables_set" id="create_points_list" x="50" y="550"><field name="VAR" id="pointsList">pointsList</field><value name="VALUE"><block type="lists_create_with" id="points_list"><mutation items="5"></mutation><value name="ADD0"><block type="variables_get" id="get_point1"><field name="VAR" id="point1">point1</field></block></value><value name="ADD1"><block type="variables_get" id="get_point2"><field name="VAR" id="point2">point2</field></block></value><value name="ADD2"><block type="variables_get" id="get_point3"><field name="VAR" id="point3">point3</field></block></value><value name="ADD3"><block type="variables_get" id="get_point4"><field name="VAR" id="point4">point4</field></block></value><value name="ADD4"><block type="variables_get" id="get_point5"><field name="VAR" id="point5">point5</field></block></value></block></value><next><block type="variables_set" id="create_weights" x="50" y="650"><field name="VAR" id="weights">weights</field><value name="VALUE"><block type="lists_create_with" id="weights_list"><mutation items="5"></mutation><value name="ADD0"><block type="math_number" id="weight1"><field name="NUM">10</field></block></value><value name="ADD1"><block type="math_number" id="weight2"><field name="NUM">60</field></block></value><value name="ADD2"><block type="math_number" id="weight3"><field name="NUM">200</field></block></value><value name="ADD3"><block type="math_number" id="weight4"><field name="NUM">30</field></block></value><value name="ADD4"><block type="math_number" id="weight5"><field name="NUM">10</field></block></value></block></value><next><block type="variables_set" id="create_bezier_wire" x="50" y="750"><field name="VAR" id="bezierWire">bezierWire</field><value name="VALUE"><block type="bitbybit.occt.shapes.wire.createBezierWeights" id="bezier_weights"><value name="Points"><block type="variables_get" id="get_points_for_bezier"><field name="VAR" id="pointsList">pointsList</field></block></value><value name="Weights"><block type="variables_get" id="get_weights_for_bezier"><field name="VAR" id="weights">weights</field></block></value><value name="Closed"><block type="logic_boolean" id="bezier_closed"><field name="BOOL">FALSE</field></block></value></block></value><next><block type="bitbybit.draw.drawAnyAsyncNoReturn" id="draw_bezier_with_options" x="50" y="850"><value name="Entity"><block type="variables_get" id="get_bezier_wire"><field name="VAR" id="bezierWire">bezierWire</field></block></value><value name="Options"><block type="bitbybit.draw.optionsOcctShapeSimple" id="bezier_draw_options"><value name="Precision"><block type="math_number" id="bezier_precision"><field name="NUM">0.01</field></block></value><value name="DrawFaces"><block type="logic_boolean" id="bezier_draw_faces"><field name="BOOL">FALSE</field></block></value><value name="DrawEdges"><block type="logic_boolean" id="bezier_draw_edges"><field name="BOOL">TRUE</field></block></value><value name="EdgeColour"><block type="text" id="bezier_edge_color"><field name="TEXT">#e4ff1a</field></block></value><value name="EdgeWidth"><block type="math_number" id="bezier_edge_width"><field name="NUM">10</field></block></value></block></value><next><block type="variables_set" id="create_polyline_ref" x="50" y="950"><field name="VAR" id="polylineRef">polylineRef</field><value name="VALUE"><block type="bitbybit.polyline.create" id="polyline_reference"><value name="Points"><block type="variables_get" id="get_points_for_polyline"><field name="VAR" id="pointsList">pointsList</field></block></value><value name="Closed"><block type="logic_boolean" id="polyline_closed"><field name="BOOL">FALSE</field></block></value></block></value><next><block type="bitbybit.draw.drawAnyAsyncNoReturn" id="draw_polyline_ref" x="50" y="1050"><value name="Entity"><block type="variables_get" id="get_polyline_ref"><field name="VAR" id="polylineRef">polylineRef</field></block></value><next><block type="variables_set" id="calc_min_weight" x="50" y="1150"><field name="VAR" id="minWeight">minWeight</field><value name="VALUE"><block type="bitbybit.vector.min" id="min_weight_calc"><value name="Vector"><block type="variables_get" id="get_weights_for_min"><field name="VAR" id="weights">weights</field></block></value></block></value><next><block type="variables_set" id="calc_max_weight" x="50" y="1250"><field name="VAR" id="maxWeight">maxWeight</field><value name="VALUE"><block type="bitbybit.vector.max" id="max_weight_calc"><value name="Vector"><block type="variables_get" id="get_weights_for_max"><field name="VAR" id="weights">weights</field></block></value></block></value><next><block type="variables_set" id="create_sphere1" x="50" y="1350"><field name="VAR" id="sphere1">sphere1</field><value name="VALUE"><block type="bitbybit.occt.shapes.solid.createSphere" id="sphere_1"><value name="Center"><block type="variables_get" id="get_point1_for_sphere"><field name="VAR" id="point1">point1</field></block></value><value name="Radius"><block type="bitbybit.math.remap" id="remap_weight1"><value name="Number"><block type="math_number" id="weight1_value"><field name="NUM">10</field></block></value><value name="FromLow"><block type="variables_get" id="get_min_weight_1"><field name="VAR" id="minWeight">minWeight</field></block></value><value name="FromHigh"><block type="variables_get" id="get_max_weight_1"><field name="VAR" id="maxWeight">maxWeight</field></block></value><value name="ToLow"><block type="math_number" id="radius_min_1"><field name="NUM">0.3</field></block></value><value name="ToHigh"><block type="math_number" id="radius_max_1"><field name="NUM">0.9</field></block></value></block></value></block></value><next><block type="variables_set" id="create_sphere2" x="50" y="1450"><field name="VAR" id="sphere2">sphere2</field><value name="VALUE"><block type="bitbybit.occt.shapes.solid.createSphere" id="sphere_2"><value name="Center"><block type="variables_get" id="get_point2_for_sphere"><field name="VAR" id="point2">point2</field></block></value><value name="Radius"><block type="bitbybit.math.remap" id="remap_weight2"><value name="Number"><block type="math_number" id="weight2_value"><field name="NUM">60</field></block></value><value name="FromLow"><block type="variables_get" id="get_min_weight_2"><field name="VAR" id="minWeight">minWeight</field></block></value><value name="FromHigh"><block type="variables_get" id="get_max_weight_2"><field name="VAR" id="maxWeight">maxWeight</field></block></value><value name="ToLow"><block type="math_number" id="radius_min_2"><field name="NUM">0.3</field></block></value><value name="ToHigh"><block type="math_number" id="radius_max_2"><field name="NUM">0.9</field></block></value></block></value></block></value><next><block type="variables_set" id="create_sphere3" x="50" y="1550"><field name="VAR" id="sphere3">sphere3</field><value name="VALUE"><block type="bitbybit.occt.shapes.solid.createSphere" id="sphere_3"><value name="Center"><block type="variables_get" id="get_point3_for_sphere"><field name="VAR" id="point3">point3</field></block></value><value name="Radius"><block type="bitbybit.math.remap" id="remap_weight3"><value name="Number"><block type="math_number" id="weight3_value"><field name="NUM">200</field></block></value><value name="FromLow"><block type="variables_get" id="get_min_weight_3"><field name="VAR" id="minWeight">minWeight</field></block></value><value name="FromHigh"><block type="variables_get" id="get_max_weight_3"><field name="VAR" id="maxWeight">maxWeight</field></block></value><value name="ToLow"><block type="math_number" id="radius_min_3"><field name="NUM">0.3</field></block></value><value name="ToHigh"><block type="math_number" id="radius_max_3"><field name="NUM">0.9</field></block></value></block></value></block></value><next><block type="variables_set" id="create_sphere4" x="50" y="1650"><field name="VAR" id="sphere4">sphere4</field><value name="VALUE"><block type="bitbybit.occt.shapes.solid.createSphere" id="sphere_4"><value name="Center"><block type="variables_get" id="get_point4_for_sphere"><field name="VAR" id="point4">point4</field></block></value><value name="Radius"><block type="bitbybit.math.remap" id="remap_weight4"><value name="Number"><block type="math_number" id="weight4_value"><field name="NUM">30</field></block></value><value name="FromLow"><block type="variables_get" id="get_min_weight_4"><field name="VAR" id="minWeight">minWeight</field></block></value><value name="FromHigh"><block type="variables_get" id="get_max_weight_4"><field name="VAR" id="maxWeight">maxWeight</field></block></value><value name="ToLow"><block type="math_number" id="radius_min_4"><field name="NUM">0.3</field></block></value><value name="ToHigh"><block type="math_number" id="radius_max_4"><field name="NUM">0.9</field></block></value></block></value></block></value><next><block type="variables_set" id="create_sphere5" x="50" y="1750"><field name="VAR" id="sphere5">sphere5</field><value name="VALUE"><block type="bitbybit.occt.shapes.solid.createSphere" id="sphere_5"><value name="Center"><block type="variables_get" id="get_point5_for_sphere"><field name="VAR" id="point5">point5</field></block></value><value name="Radius"><block type="bitbybit.math.remap" id="remap_weight5"><value name="Number"><block type="math_number" id="weight5_value"><field name="NUM">10</field></block></value><value name="FromLow"><block type="variables_get" id="get_min_weight_5"><field name="VAR" id="minWeight">minWeight</field></block></value><value name="FromHigh"><block type="variables_get" id="get_max_weight_5"><field name="VAR" id="maxWeight">maxWeight</field></block></value><value name="ToLow"><block type="math_number" id="radius_min_5"><field name="NUM">0.3</field></block></value><value name="ToHigh"><block type="math_number" id="radius_max_5"><field name="NUM">0.9</field></block></value></block></value></block></value><next><block type="variables_set" id="create_spheres_list" x="50" y="1850"><field name="VAR" id="spheres">spheres</field><value name="VALUE"><block type="lists_create_with" id="spheres_list"><mutation items="5"></mutation><value name="ADD0"><block type="variables_get" id="get_sphere1"><field name="VAR" id="sphere1">sphere1</field></block></value><value name="ADD1"><block type="variables_get" id="get_sphere2"><field name="VAR" id="sphere2">sphere2</field></block></value><value name="ADD2"><block type="variables_get" id="get_sphere3"><field name="VAR" id="sphere3">sphere3</field></block></value><value name="ADD3"><block type="variables_get" id="get_sphere4"><field name="VAR" id="sphere4">sphere4</field></block></value><value name="ADD4"><block type="variables_get" id="get_sphere5"><field name="VAR" id="sphere5">sphere5</field></block></value></block></value><next><block type="bitbybit.draw.drawAnyAsyncNoReturn" id="draw_spheres_with_options" x="50" y="1950"><value name="Entity"><block type="variables_get" id="get_spheres"><field name="VAR" id="spheres">spheres</field></block></value><value name="Options"><block type="bitbybit.draw.optionsOcctShapeSimple" id="spheres_draw_options"><value name="Precision"><block type="math_number" id="spheres_precision"><field name="NUM">0.05</field></block></value><value name="DrawFaces"><block type="logic_boolean" id="spheres_draw_faces"><field name="BOOL">TRUE</field></block></value><value name="DrawEdges"><block type="logic_boolean" id="spheres_draw_edges"><field name="BOOL">FALSE</field></block></value><value name="FaceColour"><block type="text" id="spheres_face_color"><field name="TEXT">#37ff00</field></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></xml>
// Import required DTOs and types
const { BezierWeightsDto, SphereDto } = Bit.Inputs.OCCT;
const { DrawOcctShapeSimpleOptions } = Bit.Inputs.Draw;
const { RemapNumberDto } = Bit.Inputs.Math;
const { PolylineCreateDto } = Bit.Inputs.Polyline;
type Point3 = Bit.Inputs.Base.Point3;
type Vector3 = Bit.Inputs.Base.Vector3;
type TopoDSShapePointer = Bit.Inputs.OCCT.TopoDSShapePointer;
// Get access to BitByBit functions
const { wire } = bitbybit.occt.shapes;
const { shapes } = bitbybit.occt;
const { draw, vector, polyline } = bitbybit;
const start = async () => {
// Define control points for the Bezier curve
const controlPoints: Point3[] = [
[-10, 0, 0],
[-5, 0, 3],
[0, 7, -5],
[5, 0, 3],
[10, 0, 0]
];
// Weight values - higher weights pull the curve closer to that point
const weights: number[] = [10, 60, 200, 30, 10];
// Create weighted Bezier curve
const bezierOptions = new BezierWeightsDto();
bezierOptions.points = controlPoints;
bezierOptions.weights = weights;
bezierOptions.closed = false;
const bezierWire = await wire.createBezierWeights(bezierOptions);
// Draw the Bezier curve with thick yellow line
const wireDrawOptions = new DrawOcctShapeSimpleOptions();
wireDrawOptions.precision = 0.01;
wireDrawOptions.drawFaces = false;
wireDrawOptions.drawEdges = true;
wireDrawOptions.edgeColour = "#e4ff1a";
wireDrawOptions.edgeWidth = 10;
await draw.drawAnyAsync({ entity: bezierWire, options: wireDrawOptions });
// Draw reference polyline connecting control points
const plnOptions = new PolylineCreateDto();
plnOptions.points = controlPoints;
const pln = polyline.create(plnOptions) as Bit.Inputs.Draw.Entity;
await draw.drawAnyAsync({ entity: pln });
// Calculate weight range for sphere scaling
const minWeight = vector.min({ vector: weights });
const maxWeight = vector.max({ vector: weights });
// Create spheres at control points, sized by their weights
const spherePromises = [];
for (let i = 0; i < controlPoints.length; i++) {
// Remap weight to sphere radius (0.3 to 0.9)
const remapOptions = new RemapNumberDto();
remapOptions.number = weights[i];
remapOptions.fromLow = minWeight;
remapOptions.fromHigh = maxWeight;
remapOptions.toLow = 0.3;
remapOptions.toHigh = 0.9;
const sphereOptions = new SphereDto();
sphereOptions.center = controlPoints[i];
sphereOptions.radius = bitbybit.math.remap(remapOptions);
spherePromises.push(shapes.solid.createSphere(sphereOptions));
}
const spheres = await Promise.all(spherePromises);
// Draw spheres in green
const sphereDrawOptions = new DrawOcctShapeSimpleOptions();
sphereDrawOptions.precision = 0.05;
sphereDrawOptions.drawFaces = true;
sphereDrawOptions.drawEdges = false;
sphereDrawOptions.faceColour = "#37ff00";
draw.drawAnyAsync({ entity: spheres, options: sphereDrawOptions });
};
start();



