>>> from sympy import symbols, Plot

>>> x,y,z,u,v = symbols('xyzuv')

>>> p = Plot(axes='none')

>>> from sympy import symbols, Plot

>>> x,y,z,u,v = symbols('xyzuv')

>>> p = Plot(axes='none')

Now let's plot a saddle and color it by the magnitude of its gradient:

>>> fz = x**2-y**2

>>> Fx, Fy, Fz = fz.diff(x), fz.diff(y), 0

>>> p[1] = fz, 'style=solid'

>>> p[1].color = (Fx**2 + Fy**2 + Fz**2)**(0.5)

>>> fz = x**2-y**2

>>> Fx, Fy, Fz = fz.diff(x), fz.diff(y), 0

>>> p[1] = fz, 'style=solid'

>>> p[1].color = (Fx**2 + Fy**2 + Fz**2)**(0.5)

Remember that the algorithm for coloring works like this:

- Evaluate the color function(s) across the curve or surface.
- Find the minimum and maximum value of each component.
- Scale each component to the color gradient.

>>> p[1].color = (Fx**2 + Fy**2 + Fz**2)**(0.5),

................ (0.1,0.1,0.9), (0.9,0.1,0.1)

>>> p[1].color = (Fx**2 + Fy**2 + Fz**2)**(0.5),

................ (0.1,0.1,0.9), (0.9,0.1,0.1)

Next, let's try a color gradient with four steps:

>>> gradient = [ 0.0, (0.1,0.1,0.9), 0.3, (0.1,0.9,0.1),

................ 0.7, (0.9,0.9,0.1), 1.0, (1.0,0.0,0.0) ]

>>> p[1].color = (Fx**2 + Fy**2 + Fz**2)**(0.5), gradient

>>> gradient = [ 0.0, (0.1,0.1,0.9), 0.3, (0.1,0.9,0.1),

................ 0.7, (0.9,0.9,0.1), 1.0, (1.0,0.0,0.0) ]

>>> p[1].color = (Fx**2 + Fy**2 + Fz**2)**(0.5), gradient

The other way to specify a color scheme is to give a separate function for each component r, g, b. With this syntax, the default color scheme is defined:

>>> p[1].color = z,y,x, (0.4,0.4,0.4), (0.9,0.9,0.9)

>>> p[1].color = z,y,x, (0.4,0.4,0.4), (0.9,0.9,0.9)

This maps z->red, y->green, and x->blue. In some cases, you might prefer to use the following alternative syntax:

>>> p[1].color = z,(0.4,0.9), y,(0.4,0.9), x,(0.4,0.9)

>>> p[1].color = z,(0.4,0.9), y,(0.4,0.9), x,(0.4,0.9)

You can still use multi-step gradients with three-function color schemes. When somebody uses this to visualize something useful like curvature, I'd really like to hear about it.

## 1 comment:

Wow Brian Jorgensen, I am impressed. It is so amazing what you've done, high five brother.

Post a Comment