Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reg = BoundaryDiscretizeRegion[Ball[], PlotTheme -> "SmoothShading",
- PrecisionGoal -> 1, MaxCellMeasure -> 0.1]
- gr = GraphicsComplex[MeshCoordinates[reg], MeshCells[reg, 2]];
- Graphics3D[{EdgeForm[None], gr}]
- reg = BoundaryDiscretizeRegion[Ball[], PlotTheme -> "SmoothShading",
- PrecisionGoal -> 1, MaxCellMeasure -> 0.1];
- Graphics3D[
- GraphicsComplex[
- MeshCoordinates[reg],
- {EdgeForm[], Thread[MeshCells[reg, 2], Polygon]},
- VertexNormals -> #]
- ] & /@ {Automatic, Region`Mesh`MeshCellNormals[reg, 0]} // GraphicsRow
- rplot[reg_] := Graphics3D[
- GraphicsComplex[
- MeshCoordinates[reg],
- {EdgeForm[], Thread[MeshCells[reg, 2], Polygon]},
- VertexNormals -> #]
- ] &
- reg = BoundaryDiscretizeRegion[
- RegionUnion[Ball[], Cylinder[{{0, 0, 0}, {1, 1, 1}}, 2]]];
- rplot[reg] /@ {Automatic, Region`Mesh`MeshCellNormals[reg, 0]} // GraphicsRow
- reg = BoundaryDiscretizeRegion@
- ImplicitRegion[x^2 + y^2 + z^2 + (x^2 - y^2)^2 < 4, {x, y, z}];
- rplot[reg] /@ {Automatic, Region`Mesh`MeshCellNormals[reg, 0]} // GraphicsRow
- reg = ConvexHullMesh[RandomPoint[Sphere[], 100]];
- rplot[reg] /@ {Automatic, Region`Mesh`MeshCellNormals[reg, 0]} // GraphicsRow
- meshPoints = MeshPrimitives[reg, 0] /. Point -> Sequence;
- polys = MeshPrimitives[reg, 2] /. Polygon -> Sequence;
- polysRotated = RotateRight /@ polys;
- polyVecs = polys - polysRotated;
- surfaceNorms =
- MapThread[Cross, {polyVecs[[All, 1]], polyVecs[[All, 2]]}];
- polyVertexes = MeshCells[reg, 2] /. Polygon -> Sequence;
- sharedVerticeAssoc = (Flatten /@
- Merge[{PositionIndex[polyVertexes[[All, 1]]],
- PositionIndex[polyVertexes[[All, 2]]],
- PositionIndex[polyVertexes[[All, 3]]]}, Identity]);
- SurfaceNormsAdjacentEachVertice =
- Table[Plus[meshPoints[[i]], #] & /@
- surfaceNorms[[sharedVerticeAssoc[i]]], {i, 1,
- Length[meshPoints]}];
- surfaceVectorsatEachVertex =
- Table[Riffle[
- SurfaceNormsAdjacentEachVertice[[i]], {meshPoints[[i]]}, {1, -2,
- 2}], {i, 1, Length[meshPoints]}];
- Graphics3D[{Table[
- Line /@ Partition[surfaceVectorsatEachVertex[[i]], 2], {i,
- 122}], {EdgeForm[None], gr}}]
- Graphics3D[GraphicsComplex[MeshCoordinates[reg], {EdgeForm[],Thread[MeshCells[reg, 2], Polygon]},VertexNormals -> Total /@ SurfaceNormsAdjacentEachVertice]]
- reg = BoundaryDiscretizeRegion[Ball[], PlotTheme -> "SmoothShading",
- PrecisionGoal -> 1, MaxCellMeasure -> 0.1];
- pts = MeshCoordinates[reg]; tri = MeshCells[reg, 2];
- idx = tri[[All, 1]];
- (* get neighbors for each vertex *)
- nbrs = Table[DeleteDuplicates[Flatten[List @@@ First[FindCycle[
- Extract[idx, Drop[SparseArray[Unitize[idx - k],
- Automatic, 1]["NonzeroPositions"], None, -1],
- # /. {k, a_, b_} | {b_, k, a_} | {a_, b_, k} :> (a -> b) &]]]]],
- {k, Length[pts]}];
- (* Max's method *)
- nrms = Table[Normalize[Total[With[{c = pts[[k]], vl = pts[[#]]},
- Cross[vl[[1]] - c, vl[[2]] - c]/
- ((#.# &[vl[[1]] - c]) (#.# &[vl[[2]] - c]))] & /@
- Partition[nbrs[[k]], 2, 1, 1],
- Method -> "CompensatedSummation"]], {k, Length[pts]}];
- Graphics3D[{EdgeForm[], GraphicsComplex[pts, tri, VertexNormals -> nrms]}]
- Graphics3D[{EdgeForm[], GraphicsComplex[pts, Triangle[tri], VertexNormals -> nrms],
- Arrowheads[Small],
- MapThread[Arrow[Tube[{#1, #1 + #2/5}, 0.01]] &, {pts, nrms}]}]
Add Comment
Please, Sign In to add comment