CSG (Constructive Solid Geometry) note
tags: 3D js
CSG is a methodology for constructing geometries by mesh, using algorithms capable of performing boolean operations like union or difference (A-B), among others.
vector
values
x,y,z for a point or normal
clone
return new same vector
negated
return new same negated
plus(a)
return new vector add a vector
minus(a)
this-a
times(a)
乘a
divideBy(a)
除a
dot(a)
內積
return x*a.x+y*a.y+z*a.zlerp(a,t)
t通常小於1 用來表示this 到a 之間的某個數
this-(this-a)*tlen
unit
單位為1的向量
cross
降階值
[[x ,y ,z ], [a.x ,a.y ,a.z ]]
vertex
value
- pos( vector)
- noraml (vector)
clone
flip
修改normal 方向
interpolate(a,t)
用lerp的方式產生一個介於this 與a 之間的pos and normal並用 t控制落點
plane
value
- normal 面的髮線
- w
- epsilon 可接受誤差值
clone
flip
change the side of the normal
formpoints(a,b,c)
create plane by 3 point vector and w is plane dot with fisrt verctor(position)
splitPolygon(polygon, coplanarFront, coplanarBack, front, back)
以這個面為基準將多個面區分為語法線面相同的front 或back 如果有交集則切割面
polygon
valuemagnitude
- vertices(lot of vertex)
- shared
- plane
- EPSILON(對於點是否在面上的容忍值)
clone
flip
- flip vertex
- flip plane
node
bsp:binary space partitioning tree
利用每個面的髮線區切割空間,如果空間在髮線的背面則視為true(或是包含)
value
- plane
- front=node
- back=node
- polygons=[]
clone
invert
- flip polygons
- flip plane
- flip back and front
- and change back to front 、 change front to back
clip Polygons
clipTo(bsp)
bsp:binary space partitioning tree
a和b的 bsp tree 合併=a-b的截面
+-------+ +-------+ | | | | | A | | | | +--+----+ = | + +----+--+ | +----+ | B | | | +-------+allPolygons
return combon all polygon from back and front to one array
Boolean operations
union
a.clipTo(b); b.clipTo(a); b.invert(); b.clipTo(a); b.invert(); a.build(b.allPolygons());my way
a.clipTo(b); b.clipTo(a); a.build(b.allPolygons());subtract
a.invert(); a.clipTo(b); b.clipTo(a); b.invert(); b.clipTo(a); b.invert(); a.build(b.allPolygons()); a.invert();
my way
a.invert(); a.clipTo(b); b.invert(); b.clipTo(a); a.invert(); a.build(b.allPolygons());intersect
a.invert(); b.clipTo(a); b.invert(); a.clipTo(b); b.clipTo(a); a.build(b.allPolygons()); a.invert();
another way to intersect
a.invert(); b.clipTo(a); b.invert(); a.clipTo(b); a.build(b.allPolygons()); a.invert();
links
- [other way](http: //groups.csail.mit.edu/graphics/classes/6.837/F98/talecture/)
- [paper link](https: //static1.squarespace.com/static/51bb9790e4b0510af19ea9c4/t/51bf7c34e4b0a897bf550945/1371503668974/CSG_report.pdf)
- github