4
$\begingroup$

I am new to Mathematica, and am unsure on how to start this.

I am working with a triangular lattice $\mathcal{T}$ with basis vectors $(1,0)$ and$\left(-\frac{1}{2},\frac{\sqrt{3}}{2}\right)$, and have a function $f:\mathcal{T}\to\mathbb{R}$ that is defined on this triangular lattice. I want to be able to plot this function on this triangular lattice, any help would be appreciated.

I assume first I have to create the triangular lattice $\mathcal{T}$ as say $\mathtt{T=...}$ and then perform the Plot3D command as follows: $\texttt{Plot3D[f[x,y],{x,y}$\in$T]}$.

The question is then really, how would I generate this point set $\mathtt{T}$.

$\endgroup$

1 Answer 1

5
$\begingroup$

You can do something like this

grid = Flatten[
   Table[x*{1, 0} + y*{-1/2, Sqrt[3]/2}, {x, -Pi, Pi, .25}, {y, -Pi, 
     Pi, .25}], 1];

ListPlot[grid]

enter image description here

z[{x_, y_}] := Sin[x]*Cos[y]
Z = z /@ grid;
data = Append[Transpose[grid], Z];
data = Transpose[data];
ListPlot3D[data]

enter image description here

$\endgroup$
2
  • $\begingroup$ That's perfect, thank you. $\endgroup$
    – spaceman
    Commented Aug 28, 2021 at 13:27
  • $\begingroup$ You're welcome! Glad I could help. $\endgroup$
    – Derek H
    Commented Aug 28, 2021 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.