Well Trajectory Section
Three wells drill from surface to 3,000 m and then turn into 700 m horizontal sections; trajectories are split into 40 segments colored by depth, with 5 translucent strata toggled on and off.
Business context
Well trajectory sections are a core drawing in drilling and reservoir engineering. The users are directional drilling engineers, geosteering staff and reservoir managers checking whether a well lands as designed and whether the horizontal section stays in the target zone. Data comes from MWD survey records and end-of-well reports; a single well has hundreds to thousands of survey stations, and three wells with 41 stations each at a 3,000 m total depth reflect a common development-well scale.
Survey data gives measured depth, inclination and azimuth, so minimum-curvature conversion into true vertical depth and north-south, east-west offsets happens before deck.gl, followed by a uniform scaling into scene units; vertical exaggeration and horizontal scale must be set separately or inclinations are misread. Cesium can attach to geographic coordinates but the wellbore is underground, and three.js requires custom tube geometry; LineLayer with per-segment color plus PolygonLayer strata is more direct.
Misreading centers on the depth direction: z is positive upward, so deeper wells have smaller values and the top is easily mistaken for the bottom. Vertical scale is compressed, 3,000 m becoming 360 units, so the dogleg seen on screen is not the true change in inclination. Strata are horizontal slabs of equal thickness, while real beds may dip or be faulted, so a layer boundary is not a geologic contact.
How it works
The deviation curve is generated from normalized progress t: for t ≤ 0.8 the well descends vertically to 3,000 m; for t > 0.8 depth is held constant while horizontal displacement turns smoothly out to 700 m along a smoothstep s²(3-2s), and the vertical section carries a ±12 m sine wobble so the trajectory is not a straight line. Metric coordinates are multiplied by 0.12 into scene units, turning 3,000 m into 360 units and 700 m into 84; the surface is raised to z = 180 so the whole trajectory centers on the origin while OrbitView keeps target at [0,0,0]. Each well is sampled at 41 points, adjacent points form 40 segment objects, and the three wells total 120.
LineLayer evaluates getColor per instance, whereas a whole PathLayer takes one color, so splitting by depth is what expresses the 0–3,000 m gradient; the 120 segments remain instances of one LineLayer and draw in a single call, costing only 240 vertex attributes, while one LineLayer per segment would mean 120 draw calls and 120 uniform updates. Forty segments is a compromise: finer splits show smoother color bands, but instance count and per-frame attribute uploads grow with them, and beyond 600 segments the gain on low-end devices is only visual repetition. Strata are five horizontal rectangles at alpha 16–26, at depths of 300, 900, 1,500, 2,100 and 2,700 m, with outlines at alpha 110 so layer boundaries remain visible on a dark background.
| Setting | Effect |
|---|---|
| SCALE 0.12 | Compresses 3,000 m of well depth into 360 scene units |
| SEG 40 | 40 segment instances per well, 120 across three wells |
| widthUnits: 'pixels' | Trajectory width fixed at 2.5 px, not thickening with zoom |
| PolygonLayer ×5 | Five translucent strata from 300 to 2,700 m, fill alpha 16–26 |
Note. Depth-banded coloring uses one instance per segment and 40 segments show the transition well; splitting into multiple LineLayers turns one draw call into dozens.
Source
<!--
示例:井轨迹三维剖面
要点:3 口井各拆 40 段,LineLayer 逐段着色表达 0–3000 m 深度,5 个半透明矩形叠出地层
依赖:deck.gl 9.0 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>井轨迹三维剖面</title>
<style>
html,body{height:100%;margin:0;background:#0d1117}
body{display:flex;flex-direction:column;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif;color:#e6e8ec}
.bar{position:relative;z-index:5;flex:0 0 auto;padding:8px 12px;background:#161b22;border-bottom:1px solid #252c36;
display:flex;gap:14px;align-items:center;font-size:12px;color:#8b93a1;flex-wrap:wrap}
.bar b{color:#58a6ff;font-weight:600}
.bar label{display:flex;align-items:center;gap:5px;cursor:pointer}
.bar input[type=checkbox]{accent-color:#4f9ef8}
.bar input[type=range]{width:150px;accent-color:#4f9ef8}
.bar button{font:inherit;font-size:12px;padding:3px 10px;border-radius:4px;cursor:pointer;
border:1px solid #2f3947;background:#1d242e;color:#c9d3e0}
.bar button:hover{background:#26303d}
.bar button.on{background:#2c4a7a;border-color:#4f8ad6;color:#dfe9ff}
.bar .sep{width:1px;height:18px;background:#2a313c;margin:0 4px}
#cv{flex:1 1 auto;min-height:0;width:100%;display:block}
</style>
</head>
<body>
<div class="bar">
<span>井 3 口 · 40 段/井 · 深 3000 m · 水平段 700 m</span>
<span class="sep"></span>
<label><input id="strata" type="checkbox" checked>显示地层</label>
<span>浅 绿 → 深 紫</span>
</div>
<canvas id="cv"></canvas>
<script src="https://cdn.jsdelivr.net/npm/deck.gl@9.0.35/dist.min.js"></script>
<script>
(function () {
'use strict';
if (typeof deck === 'undefined') {
document.body.innerHTML =
'<div style="padding:24px;color:#ff8c74">deck.gl 加载失败,请检查能否访问 cdn.jsdelivr.net</div>';
return;
}
var SCALE = 0.12, VERT = 3000, LAT = 700, SEG = 40, SURFACE_Z = 180;
var i, j;
var DEFS = [
{ name: 'W-1', x: -150, y: -55, dx: 1.00, dy: 0.10 },
{ name: 'W-2', x: 10, y: 60, dx: -0.15, dy: 1.00 },
{ name: 'W-3', x: 165, y: -35, dx: -1.00, dy: -0.45 }
];
var wells = [], segs = [];
for (i = 0; i < DEFS.length; i++) {
var def = DEFS[i];
var path = [];
for (j = 0; j <= SEG; j++) {
var t = j / SEG;
var depth = t <= 0.8 ? VERT * (t / 0.8) : VERT;
var s = t <= 0.8 ? 0 : (t - 0.8) / 0.2;
var lat = LAT * s * s * (3 - 2 * s);
var wob = Math.sin(t * 7.5 + i * 2.1) * 12;
path.push([
def.x + def.dx * (lat + wob) * SCALE,
def.y + def.dy * lat * SCALE,
SURFACE_Z - depth * SCALE
]);
}
wells.push({ name: def.name, head: path[0] });
for (j = 0; j < SEG; j++) {
var tm = (j + 0.5) / SEG;
segs.push({ s: path[j], t: path[j + 1], d: tm <= 0.8 ? tm / 0.8 : 1 });
}
}
var STOPS = [
[86, 214, 168], [120, 200, 200], [246, 186, 78],
[210, 150, 220], [176, 132, 255]
];
var LUT = [];
for (i = 0; i < 24; i++) {
var u = i / 23 * (STOPS.length - 1);
var k = Math.min(STOPS.length - 2, Math.floor(u));
var f = u - k;
LUT.push([
Math.round(STOPS[k][0] + (STOPS[k + 1][0] - STOPS[k][0]) * f),
Math.round(STOPS[k][1] + (STOPS[k + 1][1] - STOPS[k][1]) * f),
Math.round(STOPS[k][2] + (STOPS[k + 1][2] - STOPS[k][2]) * f),
240
]);
}
var strata = [];
for (i = 0; i < 5; i++) {
var z = SURFACE_Z - (300 + i * 600) * SCALE;
strata.push({
poly: [[-260, -130, z], [260, -130, z], [260, 130, z], [-260, 130, z]],
c: i % 2 ? [70, 112, 152, 26] : [86, 122, 160, 16]
});
}
var showStrata = true;
function buildLayers() {
var layers = [];
if (showStrata) {
layers.push(new deck.PolygonLayer({
id: 'strata-sheets',
data: strata,
coordinateSystem: deck.COORDINATE_SYSTEM.CARTESIAN,
getPolygon: function (d) { return d.poly; },
getFillColor: function (d) { return d.c; },
getLineColor: [96, 150, 200, 110],
getLineWidth: 1,
lineWidthUnits: 'pixels',
stroked: true,
filled: true,
pickable: false
}));
}
layers.push(new deck.LineLayer({
id: 'well-segments',
data: segs,
coordinateSystem: deck.COORDINATE_SYSTEM.CARTESIAN,
getSourcePosition: function (d) { return d.s; },
getTargetPosition: function (d) { return d.t; },
getColor: function (d) { return LUT[Math.min(23, (d.d * 23) | 0)]; },
getWidth: 2.5,
widthUnits: 'pixels',
widthMinPixels: 2,
pickable: false
}));
layers.push(new deck.ScatterplotLayer({
id: 'well-heads',
data: wells,
coordinateSystem: deck.COORDINATE_SYSTEM.CARTESIAN,
getPosition: function (d) { return d.head; },
getRadius: 6,
radiusUnits: 'pixels',
getFillColor: [255, 200, 96, 245],
stroked: true,
getLineColor: [30, 24, 12, 220],
getLineWidth: 1.5,
lineWidthUnits: 'pixels',
pickable: false
}));
layers.push(new deck.TextLayer({
id: 'well-labels',
data: wells,
coordinateSystem: deck.COORDINATE_SYSTEM.CARTESIAN,
getPosition: function (d) { return d.head; },
getText: function (d) { return d.name; },
getSize: 11,
sizeUnits: 'pixels',
getPixelOffset: [0, -10],
getTextAnchor: 'middle',
getAlignmentBaseline: 'bottom',
getColor: [255, 208, 120, 235],
outlineWidth: 2,
outlineColor: [13, 17, 23, 230],
fontSettings: { sdf: true },
fontFamily: 'monospace',
pickable: false
}));
return layers;
}
var deckgl = new deck.Deck({
canvas: 'cv',
width: '100%',
height: '100%',
views: new deck.OrbitView({ target: [0, 0, 0], fovy: 30 }),
initialViewState: { target: [0, 0, 0], rotationX: 30, rotationOrbit: -34, zoom: 0.34 },
controller: true,
layers: buildLayers()
});
document.getElementById('strata').addEventListener('change', function () {
showStrata = this.checked;
deckgl.setProps({ layers: buildLayers() });
});
window.__deck = deckgl;
})();
</script>
</body>
</html>