Skip to content

Commit

Permalink
helicoid!
Browse files Browse the repository at this point in the history
  • Loading branch information
paolini committed Aug 12, 2024
1 parent 7457ca0 commit 4773fbf
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 56 deletions.
71 changes: 51 additions & 20 deletions js/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ export class Catenoid extends Surf {
this.addQuad(1,2,5,4)
this.addQuad(2,0,3,5)
}

run() {
this.triangulate(1)
this.evolveMeanCurvature(0.05,20)
this.triangulate(0.5)
this.evolveMeanCurvature(0.05,20)
}
}

export class Cube extends Surf {
Expand All @@ -77,18 +70,18 @@ export class Cube extends Surf {
const vm11 = this.addVertex(0.5*sx,0.7*sy,0.7*sz)

// 12 borders
const bx00 = this.addBorder(t => [t*sx, 0, 0], 0.0)
const bx01 = this.addBorder(t => [t*sx, 0,sz], 0.0)
const bx10 = this.addBorder(t => [t*sx,sy, 0], 0.0)
const bx11 = this.addBorder(t => [t*sx,sy,sz], 0.0)
const by00 = this.addBorder(t => [ 0,t*sy, 0], 0.0)
const by01 = this.addBorder(t => [sx,t*sy, 0], 0.0)
const by10 = this.addBorder(t => [ 0,t*sy,sz], 0.0)
const by11 = this.addBorder(t => [sx,t*sy,sz], 0.0)
const bz00 = this.addBorder(t => [ 0, 0,t*sz], 0.0)
const bz01 = this.addBorder(t => [ 0,sy,t*sz], 0.0)
const bz10 = this.addBorder(t => [sx, 0,t*sz], 0.0)
const bz11 = this.addBorder(t => [sx,sy,t*sz], 0.0)
const bx00 = this.addBorder(t => [t*sx, 0, 0], 1.0, false)
const bx01 = this.addBorder(t => [t*sx, 0,sz], 1.0, false)
const bx10 = this.addBorder(t => [t*sx,sy, 0], 1.0, false)
const bx11 = this.addBorder(t => [t*sx,sy,sz], 1.0, false)
const by00 = this.addBorder(t => [ 0,t*sy, 0], 1.0, false)
const by01 = this.addBorder(t => [sx,t*sy, 0], 1.0, false)
const by10 = this.addBorder(t => [ 0,t*sy,sz], 1.0, false)
const by11 = this.addBorder(t => [sx,t*sy,sz], 1.0, false)
const bz00 = this.addBorder(t => [ 0, 0,t*sz], 1.0, false)
const bz01 = this.addBorder(t => [ 0,sy,t*sz], 1.0, false)
const bz10 = this.addBorder(t => [sx, 0,t*sz], 1.0, false)
const bz11 = this.addBorder(t => [sx,sy,t*sz], 1.0, false)

// fix border vertices
this.addBorderVertex(0,bx00,v000)
Expand Down Expand Up @@ -133,4 +126,42 @@ export class Cube extends Surf {
this.addQuad(vm00,vm10,vm11,vm01)
}
}


export class Helicoid extends Surf {
constructor(R:number=1.0,r:number=0, h:number=1.0, N:number=2) {
super()

const PERIOD = 4.0
this.addBorder(t => {
if (t<2.0) {
if (t<1.0) { // t in [0,1]
return [r+t*(R-r),0,-h]
} else { // t in [1,2]
const a=N*2.0*PI*(t-1.0)
return [R*cos(a),R*sin(a),(t-1.5)*2.0*h]
}
} else {
if (t<3.0) { // t in [2,3]
const a=N*2.0*PI
const s=(3.0-t)*(R-r)
return [(r+s)*cos(a),(r+s)*sin(a),h]
} else { // t in [3,4]
const a=N*2.0*PI*(4.0-t)
return [r*cos(a),r*sin(a),(3.5-t)*2.0*h]
}
}
}, PERIOD)

this.addBorderVertex(0)
this.addBorderVertex(PERIOD/3)
this.addBorderVertex(2*PERIOD/3)
this.addTriangle(0,1,2)
}

run() {
for (let i=0; i<10; i++) {
this.triangulate()
this.evolveMeanCurvature(0.05,20)
}
}
}
4 changes: 2 additions & 2 deletions js/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as THREE from 'three'
import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'

import {Pringle,Catenoid,Cube} from './examples'
import {Pringle,Catenoid,Cube,Helicoid} from './examples'

const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000)
Expand All @@ -12,7 +12,7 @@ const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)

const surf = new Cube()
const surf = new Helicoid()

// Create a material
const material = new THREE.MeshPhongMaterial();
Expand Down
39 changes: 5 additions & 34 deletions js/surf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class Surf {
f: (t:number)=>Vector,
indices: [Index,number][]
period: number,
closed: boolean
})[]

constructor() {
Expand All @@ -25,13 +26,10 @@ export default class Surf {
* @param period period of parameter if curve is closed, 0 if it is open
* @returns the index of the newly created border
*/
addBorder(f:((number)=>Vector), period: number = 1.0): Index {
addBorder(f:((number)=>Vector), period: number = 1.0, closed: boolean=true): Index {
const borderIndex = this.borders.length
this.borders.push({
f: f,
indices: [],
period: period,
})
const indices = []
this.borders.push({f, indices, period, closed})
return borderIndex
}

Expand Down Expand Up @@ -236,7 +234,7 @@ export default class Surf {
const t = indices[i][1]
const tt = indices[ii][1]
let ttt = 0.5*(t+tt)
if (border.period && Math.abs(tt-t) > 0.5*border.period) {
if (border.closed && Math.abs(tt-t) > 0.5*border.period) {
ttt -= 0.5*border.period
if (ttt<0) ttt += border.period
}
Expand All @@ -253,33 +251,6 @@ export default class Surf {
return false
}

evolve() {
const N_TRIANGLES = this.indices.length / 3
const N_VERTICES = this.vertices.length / 3

function vertex(i) { return this.getVertex(i)}

for (let i=0; i<N_TRIANGLES; i++) {
const a = this.indices[3*i]
const b = this.indices[3*i+1]
const c = this.indices[3*i+2]
const area = compute_area(vertex(a), vertex(b), vertex(c))

/* WIP, see vertex.cc vertex::grad */
const v = vector_diff(vertex(b), vertex(a))
const w = vector_diff(vertex(c), vertex(a))


const grad: Vector = scale_vector(1/(2*area),
vector_diff(scale_vector(number_product(v,w),vector_sum(v,w)),
vector_sum(
scale_vector(squared_norm(v),w),
scale_vector(squared_norm(w),v))))

/* WIP */
}
}

printVertices() {
const vertices = this.vertices
for (let i=0; 3*i<vertices.length; i++) {
Expand Down

0 comments on commit 4773fbf

Please sign in to comment.