|
| 1 | +import type { ArrayType } from "./math/types"; |
| 2 | + |
1 | 3 | export type vec3 = [number,number,number]; |
2 | 4 |
|
3 | 5 |
|
@@ -61,4 +63,39 @@ export function build_color_text(color_grid:vec3[][], base_text:string){ |
61 | 63 | return html; |
62 | 64 | } |
63 | 65 |
|
| 66 | +function get_rect_edge(x1:number, y1:number,x2:number,y2:number,thickness:number) : string{ |
| 67 | + const dx = x2 - x1; |
| 68 | + const dy = y2 - y1; |
| 69 | + const len = Math.sqrt(dx * dx + dy * dy); |
| 70 | + const ang = Math.atan2(dy, dx) * (180 / Math.PI); |
| 71 | + return `<rect x="0" y="${-thickness / 2}" width="${len}" height="${thickness}" transform="translate(${x1} ${y1}) rotate(${ang})"/>`; |
| 72 | +} |
| 73 | + |
| 74 | +export function build_3d_svg(vertices:ArrayType, use_rect:boolean, stride:number = 4):string{ |
| 75 | + const n = vertices.length; |
| 76 | + let html = ""; |
| 77 | + |
| 78 | + const thickness = 0.005; |
| 79 | + |
| 80 | + |
| 81 | + for(let i = 0; i < n ; i+=6){ |
| 82 | + const x1 = vertices[i]; |
| 83 | + const y1 = vertices[i+1]; |
| 84 | + |
| 85 | + const x2 = vertices[i+2]; |
| 86 | + const y2 = vertices[i+3]; |
| 87 | + |
| 88 | + const x3 = vertices[i+4]; |
| 89 | + const y3 = vertices[i+5]; |
| 90 | + if(use_rect){ |
| 91 | + html+= get_rect_edge(x1,y1,x2,y2,thickness); |
| 92 | + html+= get_rect_edge(x2,y2,x3,y3,thickness); |
| 93 | + html+= get_rect_edge(x3,y3,x1,y1,thickness); |
| 94 | + continue; |
| 95 | + } |
| 96 | + html += `<polygon points = "${x1},${y1} ${x2},${y2} ${x3},${y3}"/>`; |
| 97 | + } |
| 98 | + return html; |
| 99 | +} |
| 100 | + |
64 | 101 |
|
0 commit comments