Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

""" 

Implicit Plots 

""" 

from __future__ import absolute_import 

from .implicit_surface import ImplicitSurface 

 

 

def implicit_plot3d(f, xrange, yrange, zrange, **kwds): 

r""" 

Plots an isosurface of a function. 

 

INPUT: 

 

- ``f`` - function 

 

- ``xrange`` - a 2-tuple (x_min, x_max) or a 3-tuple (x, x_min, x_max) 

 

- ``yrange`` - a 2-tuple (y_min, y_may) or a 3-tuple (y, y_min, y_may) 

 

- ``zrange`` - a 2-tuple (z_min, z_maz) or a 3-tuple (z, z_min, z_maz) 

 

- ``plot_points`` - (default: "automatic", which is 40) the number of 

function evaluations in each direction. (The number of cubes in the 

marching cubes algorithm will be one less than this). Can be a triple of 

integers, to specify a different resolution in each of x,y,z. 

 

- ``contour`` - (default: 0) plot the isosurface f(x,y,z)==contour. Can be a 

list, in which case multiple contours are plotted. 

 

- ``region`` - (default: None) If region is given, it must be a Python 

callable. Only segments of the surface where region(x,y,z) returns a 

number >0 will be included in the plot. (Note that returning a Python 

boolean is acceptable, since True == 1 and False == 0). 

 

EXAMPLES:: 

 

sage: var('x,y,z') 

(x, y, z) 

 

A simple sphere:: 

 

sage: implicit_plot3d(x^2+y^2+z^2==4, (x,-3,3), (y,-3,3), (z,-3,3)) 

Graphics3d Object 

 

.. PLOT:: 

 

var('x,y,z') 

F = x**2 + y**2 + z**2 

P = implicit_plot3d(F==4, (x,-3,3), (y,-3,3), (z,-3,3)) 

sphinx_plot(P) 

 

A nested set of spheres with a hole cut out:: 

 

sage: implicit_plot3d((x^2 + y^2 + z^2), (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60, contour=[1,3,5], 

....: region=lambda x,y,z: x<=0.2 or y>=0.2 or z<=0.2, color='aquamarine').show(viewer='tachyon') 

 

.. PLOT:: 

 

var('x,y,z') 

F = x**2 + y**2 + z**2 

P = implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60, contour=[1,3,5], 

region=lambda x,y,z: x<=0.2 or y>=0.2 or z<=0.2, color='aquamarine') 

sphinx_plot(P) 

 

A very pretty example, attributed to Douglas Summers-Stay (`archived page 

<http://web.archive.org/web/20080529033738/http://iat.ubalt.edu/summers/math/platsol.htm>`_):: 

 

sage: T = RDF(golden_ratio) 

sage: F = 2 - (cos(x+T*y) + cos(x-T*y) + cos(y+T*z) + cos(y-T*z) + cos(z-T*x) + cos(z+T*x)) 

sage: r = 4.77 

sage: implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), plot_points=40, color='darkkhaki').show(viewer='tachyon') 

 

.. PLOT:: 

 

var('x,y,z') 

T = RDF(golden_ratio) 

F = 2 - (cos(x+T*y) + cos(x-T*y) + cos(y+T*z) + cos(y-T*z) + cos(z-T*x) + cos(z+T*x)) 

r = 4.77 

V = implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), plot_points=40, color='darkkhaki') 

sphinx_plot(V) 

 

As I write this (but probably not as you read it), it's almost Valentine's 

day, so let's try a heart (from http://mathworld.wolfram.com/HeartSurface.html) 

 

:: 

 

sage: F = (x^2+9/4*y^2+z^2-1)^3 - x^2*z^3 - 9/(80)*y^2*z^3 

sage: r = 1.5 

sage: implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), plot_points=80, color='red', smooth=False).show(viewer='tachyon') 

 

.. PLOT:: 

 

var('x,y,z') 

F = (x**2+9.0/4.0*y**2+z**2-1)**3 - x**2*z**3 - 9.0/(80)*y**2*z**3 

r = 1.5 

V = implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), plot_points=80, color='red', smooth=False) 

sphinx_plot(V) 

 

The same examples also work with the default Jmol viewer; for example:: 

 

sage: T = RDF(golden_ratio) 

sage: F = 2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) + cos(y - T*z) + cos(z - T*x) + cos(z + T*x)) 

sage: r = 4.77 

sage: implicit_plot3d(F, (x,-r,r), (y,-r,r), (z,-r,r), plot_points=40, color='deepskyblue').show() 

 

Here we use smooth=True with a Tachyon graph:: 

 

sage: implicit_plot3d(x^2 + y^2 + z^2, (x,-2,2), (y,-2,2), (z,-2,2), contour=4, color='deepskyblue', smooth=True) 

Graphics3d Object 

 

.. PLOT:: 

 

var('x,y,z') 

F = x**2 + y**2 + z**2 

P = implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), contour=4, color='deepskyblue', smooth=True) 

sphinx_plot(P) 

 

We explicitly specify a gradient function (in conjunction with smooth=True) 

and invert the normals:: 

 

sage: gx = lambda x, y, z: -(2*x + y^2 + z^2) 

sage: gy = lambda x, y, z: -(x^2 + 2*y + z^2) 

sage: gz = lambda x, y, z: -(x^2 + y^2 + 2*z) 

sage: implicit_plot3d(x^2+y^2+z^2, (x,-2,2), (y,-2,2), (z,-2,2), contour=4, 

....: plot_points=40, smooth=True, gradient=(gx, gy, gz)).show(viewer='tachyon') 

 

.. PLOT:: 

 

var('x,y,z') 

gx = lambda x, y, z: -(2*x + y**2 + z**2) 

gy = lambda x, y, z: -(x**2 + 2*y + z**2) 

gz = lambda x, y, z: -(x**2 + y**2 + 2*z) 

P = implicit_plot3d(x**2+y**2+z**2, (x,-2,2), (y,-2,2), (z,-2,2), contour=4, 

plot_points=40, smooth=True, gradient=(gx, gy, gz)) 

sphinx_plot(P) 

 

A graph of two metaballs interacting with each other:: 

 

sage: def metaball(x0, y0, z0): return 1 / ((x-x0)^2+(y-y0)^2+(z-z0)^2) 

sage: implicit_plot3d(metaball(-0.6,0,0) + metaball(0.6,0,0), (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60, contour=2, color='seagreen') 

Graphics3d Object 

 

.. PLOT:: 

 

var('x,y,z') 

def metaball(x0, y0, z0): return 1 / ((x-x0)**2+(y-y0)**2+(z-z0)**2) 

P = implicit_plot3d(metaball(-0.6,0,0) + metaball(0.6,0,0), (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60, contour=2, color='seagreen') 

sphinx_plot(P) 

 

One can color the surface according to a coloring function and a colormap:: 

 

sage: t = (sin(3*z)**2).function(x,y,z) 

sage: cm = colormaps.gist_rainbow 

sage: G = implicit_plot3d(x^2 + y^2 + z^2, (x,-2,2), (y,-2,2), (z,-2, 2), 

....: contour=4, color=(t,cm), plot_points=100) 

sage: G.show(viewer='tachyon') 

 

.. PLOT:: 

 

var('x,y,z') 

t = (sin(3*z)**2).function(x,y,z) 

cm = colormaps.gist_rainbow 

G = implicit_plot3d(x**2 + y**2 + z**2, (x,-2,2), (y,-2,2), (z,-2, 2), 

contour=4, color=(t,cm), plot_points=60) 

sphinx_plot(G) 

 

Here is another colored example:: 

 

sage: x, y, z = var('x,y,z') 

sage: t = (x).function(x,y,z) 

sage: cm = colormaps.PiYG 

sage: G = implicit_plot3d(x^4 + y^2 + z^2, (x,-2,2), 

....: (y,-2,2),(z,-2,2), contour=4, color=(t,cm), plot_points=40) 

sage: G 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

t = (x).function(x,y,z) 

cm = colormaps.PiYG 

G = implicit_plot3d(x**4 + y**2 + z**2, (x,-2,2), 

(y,-2,2),(z,-2,2), contour=4, color=(t,cm), plot_points=40) 

sphinx_plot(G) 

 

.. WARNING:: 

 

This kind of coloring using a colormap can be visualized using 

Jmol, Tachyon (option ``viewer='tachyon'``) and Canvas3D 

(option ``viewer='canvas3d'`` in the notebook). 

 

MANY MORE EXAMPLES: 

 

A kind of saddle:: 

 

sage: implicit_plot3d(x^3 + y^2 - z^2, (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60, contour=0, color='lightcoral') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(x**3 + y**2 - z**2, (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60, contour=0, color='lightcoral') 

sphinx_plot(G) 

 

A smooth surface with six radial openings:: 

 

sage: implicit_plot3d(-(cos(x) + cos(y) + cos(z)), (x,-4,4), (y,-4,4), (z,-4,4), color='orchid') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(-(cos(x) + cos(y) + cos(z)), (x,-4,4), (y,-4,4), (z,-4,4), color='orchid') 

sphinx_plot(G) 

 

A cube composed of eight conjoined blobs:: 

 

sage: F = x^2 + y^2 + z^2 + cos(4*x) + cos(4*y) + cos(4*z) - 0.2 

sage: implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), color='mediumspringgreen') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F = x**2 + y**2 + z**2 + cos(4*x) + cos(4*y) + cos(4*z) - 0.2 

G = implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), color='mediumspringgreen') 

sphinx_plot(G) 

 

A variation of the blob cube featuring heterogeneously sized blobs:: 

 

sage: F = x^2 + y^2 + z^2 + sin(4*x) + sin(4*y) + sin(4*z) - 1 

sage: implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), color='lavenderblush') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F = x**2 + y**2 + z**2 + sin(4*x) + sin(4*y) + sin(4*z) - 1 

G = implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), color='lavenderblush') 

sphinx_plot(G) 

 

A Klein bottle:: 

 

sage: G = x^2 + y^2 + z^2 

sage: F = (G+2*y-1)*((G-2*y-1)^2-8*z^2) + 16*x*z*(G-2*y-1) 

sage: implicit_plot3d(F, (x,-3,3), (y,-3.1,3.1), (z,-4,4), color='moccasin') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = x**2 + y**2 + z**2 

F = (G+2*y-1)*((G-2*y-1)**2-8*z**2)+16*x*z*(G-2*y-1) 

G = implicit_plot3d(F, (x,-3,3), (y,-3.1,3.1), (z,-4,4), color='moccasin') 

sphinx_plot(G) 

 

A lemniscate:: 

 

sage: F = 4*x^2*(x^2+y^2+z^2+z) + y^2*(y^2+z^2-1) 

sage: implicit_plot3d(F, (x,-0.5,0.5), (y,-1,1), (z,-1,1), color='deeppink') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F = 4*x**2*(x**2+y**2+z**2+z) + y**2*(y**2+z**2-1) 

G = implicit_plot3d(F, (x,-0.5,0.5), (y,-1,1), (z,-1,1), color='deeppink') 

sphinx_plot(G) 

 

Drope:: 

 

sage: implicit_plot3d(z - 4*x*exp(-x^2-y^2), (x,-2,2), (y,-2,2), (z,-1.7,1.7), color='darkcyan') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(z - 4*x*exp(-x**2-y**2), (x,-2,2), (y,-2,2), (z,-1.7,1.7), color='darkcyan') 

sphinx_plot(G) 

 

A cube with a circular aperture on each face:: 

 

sage: F = ((1/2.3)^2 * (x^2 + y^2 + z^2))^(-6) + ((1/2)^8 * (x^8 + y^8 + z^8))^6 - 1 

sage: implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), color='palevioletred') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F = ((1/2.3)**2 * (x**2 + y**2 + z**2))**(-6) + ((1/2)**8 * (x**8 + y**8 + z**8))**6 - 1 

G = implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), color='palevioletred') 

sphinx_plot(G) 

 

A simple hyperbolic surface:: 

 

sage: implicit_plot3d(x^2 + y - z^2, (x,-1,1), (y,-1,1), (z,-1,1), color='darkslategray') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(x**2 + y - z**2, (x,-1,1), (y,-1,1), (z,-1,1), color='darkslategray') 

sphinx_plot(G) 

 

A hyperboloid:: 

 

sage: implicit_plot3d(x^2 + y^2 - z^2 -0.3, (x,-2,2), (y,-2,2), (z,-1.8,1.8), color='honeydew') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(x**2 + y**2 - z**2 -0.3, (x,-2,2), (y,-2,2), (z,-1.8,1.8), color='honeydew') 

sphinx_plot(G) 

 

Dupin cyclide (:wikipedia:`Dupin_cyclide`) :: 

 

sage: x, y, z , a, b, c, d = var('x,y,z,a,b,c,d') 

sage: a = 3.5 

sage: b = 3 

sage: c = sqrt(a^2 - b^2) 

sage: d = 2 

sage: F = (x^2 + y^2 + z^2 + b^2 - d^2)^2 - 4*(a*x-c*d)^2 - 4*b^2*y^2 

sage: implicit_plot3d(F, (x,-6,6), (y,-6,6), (z,-6,6), color='seashell') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z , a, b, c, d = var('x,y,z,a,b,c,d') 

a = 3.5 

b = 3 

c = sqrt(a**2 - b**2) 

d = 2 

F = (x**2 + y**2 + z**2 + b**2 - d**2)**2 - 4*(a*x-c*d)**2 - 4*b**2*y**2 

G = implicit_plot3d(F, (x,-6,6), (y,-6,6), (z,-6,6), color='seashell') 

sphinx_plot(G) 

 

Sinus:: 

 

sage: implicit_plot3d(sin(pi*((x)^2+(y)^2))/2 + z, (x,-1,1), (y,-1,1), (z,-1,1), color='rosybrown') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(sin(pi*((x)**2+(y)**2))/2 + z, (x,-1,1), (y,-1,1), (z,-1,1), color='rosybrown') 

sphinx_plot(G) 

 

A torus:: 

 

sage: implicit_plot3d((sqrt(x*x+y*y)-3)^2 + z*z - 1, (x,-4,4), (y,-4,4), (z,-1,1), color='indigo') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d((sqrt(x*x+y*y)-3)**2 + z*z - 1, (x,-4,4), (y,-4,4), (z,-1,1), color='indigo') 

sphinx_plot(G) 

 

An octahedron:: 

 

sage: implicit_plot3d(abs(x) + abs(y) + abs(z) - 1, (x,-1,1), (y,-1,1), (z,-1,1), color='olive') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(abs(x) + abs(y) + abs(z) - 1, (x,-1,1), (y,-1,1), (z,-1,1), color='olive') 

sphinx_plot(G) 

 

A cube:: 

 

sage: implicit_plot3d(x^100 + y^100 + z^100 - 1, (x,-2,2), (y,-2,2), (z,-2,2), color='lightseagreen') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(x**100 + y**100 + z**100 - 1, (x,-2,2), (y,-2,2), (z,-2,2), color='lightseagreen') 

sphinx_plot(G) 

 

Toupie:: 

 

sage: implicit_plot3d((sqrt(x*x+y*y)-3)^3 + z*z - 1, (x,-4,4), (y,-4,4), (z,-6,6), color='mintcream') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d((sqrt(x*x+y*y)-3)**3 + z*z - 1, (x,-4,4), (y,-4,4), (z,-6,6), color='mintcream') 

sphinx_plot(G) 

 

A cube with rounded edges:: 

 

sage: F = x^4 + y^4 + z^4 - (x^2 + y^2 + z^2) 

sage: implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), color='mediumvioletred') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F = x**4 + y**4 + z**4 - (x**2 + y**2 + z**2) 

G = implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), color='mediumvioletred') 

sphinx_plot(G) 

 

Chmutov:: 

 

sage: F = x^4 + y^4 + z^4 - (x^2 + y^2 + z^2 - 0.3) 

sage: implicit_plot3d(F, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1.5,1.5), color='lightskyblue') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F = x**4 + y**4 + z**4 - (x**2 + y**2 + z**2 - 0.3) 

G = implicit_plot3d(F, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1.5,1.5), color='lightskyblue') 

sphinx_plot(G) 

 

Further Chmutov:: 

 

sage: F = 2*(x^2*(3-4*x^2)^2+y^2*(3-4*y^2)^2+z^2*(3-4*z^2)^2) - 3 

sage: implicit_plot3d(F, (x,-1.3,1.3), (y,-1.3,1.3), (z,-1.3,1.3), color='darksalmon') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F = 2*(x**2*(3-4*x**2)**2+y**2*(3-4*y**2)**2+z**2*(3-4*z**2)**2) - 3 

G = implicit_plot3d(F, (x,-1.3,1.3), (y,-1.3,1.3), (z,-1.3,1.3), color='darksalmon') 

sphinx_plot(G) 

 

Clebsch surface:: 

 

sage: F_1 = 81 * (x^3+y^3+z^3) 

sage: F_2 = 189 * (x^2*(y+z)+y^2*(x+z)+z^2*(x+y)) 

sage: F_3 = 54 * x * y * z 

sage: F_4 = 126 * (x*y+x*z+y*z) 

sage: F_5 = 9 * (x^2+y^2+z^2) 

sage: F_6 = 9 * (x+y+z) 

sage: F = F_1 - F_2 + F_3 + F_4 - F_5 + F_6 + 1 

sage: implicit_plot3d(F, (x,-1,1), (y,-1,1), (z,-1,1), color='yellowgreen') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F_1 = 81 * (x**3+y**3+z**3) 

F_2 = 189 * (x**2*(y+z)+y**2*(x+z)+z**2*(x+y)) 

F_3 = 54 * x * y * z 

F_4 = 126 * (x*y+x*z+y*z) 

F_5 = 9 * (x**2+y**2+z**2) 

F_6 = 9 * (x+y+z) 

F = F_1 - F_2 + F_3 + F_4 - F_5 + F_6 + 1 

G = implicit_plot3d(F, (x,-1,1), (y,-1,1), (z,-1,1), color='yellowgreen') 

sphinx_plot(G) 

 

Looks like a water droplet:: 

 

sage: implicit_plot3d(x^2 +y^2 -(1-z)*z^2, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1,1), color='bisque') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(x**2 +y**2 -(1-z)*z**2, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1,1), color='bisque') 

sphinx_plot(G) 

 

Sphere in a cage:: 

 

sage: F = (x^8+z^30+y^8-(x^4 + z^50 + y^4 -0.3)) * (x^2+y^2+z^2-0.5) 

sage: implicit_plot3d(F, (x,-1.2,1.2), (y,-1.3,1.3), (z,-1.5,1.5), color='firebrick') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F = (x**8+z**30+y**8-(x**4 + z**50 + y**4 -0.3)) * (x**2+y**2+z**2-0.5) 

G = implicit_plot3d(F, (x,-1.2,1.2), (y,-1.3,1.3), (z,-1.5,1.5), color='firebrick') 

sphinx_plot(G) 

 

Ortho circle:: 

 

sage: F = ((x^2+y^2-1)^2+z^2) * ((y^2+z^2-1)^2+x^2) * ((z^2+x^2-1)^2+y^2)-0.075^2 * (1+3*(x^2+y^2+z^2)) 

sage: implicit_plot3d(F, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1.5,1.5), color='lemonchiffon') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F = ((x**2+y**2-1)**2+z**2) * ((y**2+z**2-1)**2+x**2) * ((z**2+x**2-1)**2+y**2)-0.075**2 * (1+3*(x**2+y**2+z**2)) 

G = implicit_plot3d(F, (x,-1.5,1.5), (y,-1.5,1.5), (z,-1.5,1.5), color='lemonchiffon') 

sphinx_plot(G) 

 

Cube sphere:: 

 

sage: F = 12 - ((1/2.3)^2 *(x^2 + y^2 + z^2))^-6 - ((1/2)^8 * (x^8 + y^8 + z^8))^6 

sage: implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), color='rosybrown') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

F = 12 - ((1/2.3)**2 *(x**2 + y**2 + z**2))**-6 - ( (1/2)**8 * (x**8 + y**8 + z**8) )**6 

G = implicit_plot3d(F, (x,-2,2), (y,-2,2), (z,-2,2), color='rosybrown') 

sphinx_plot(G) 

 

Two cylinders intersect to make a cross:: 

 

sage: implicit_plot3d((x^2+y^2-1) * (x^2+z^2-1) - 1, (x,-3,3), (y,-3,3), (z,-3,3), color='burlywood') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d((x**2+y**2-1) * (x**2+z**2-1) - 1, (x,-3,3), (y,-3,3), (z,-3,3), color='burlywood') 

sphinx_plot(G) 

 

Three cylinders intersect in a similar fashion:: 

 

sage: implicit_plot3d((x^2+y^2-1) * (x^2+z^2-1) * (y^2+z^2-1)-1, (x,-3,3), (y,-3,3), (z,-3,3), color='aqua') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d((x**2+y**2-1) * (x**2+z**2-1) * (y**2+z**2-1)-1, (x,-3,3), (y,-3,3), (z,-3,3), color='aqua') 

sphinx_plot(G) 

 

A sphere-ish object with twelve holes, four on each XYZ plane:: 

 

sage: implicit_plot3d(3*(cos(x)+cos(y)+cos(z)) + 4*cos(x)*cos(y)*cos(z), (x,-3,3), (y,-3,3), (z,-3,3), color='orangered') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(3*(cos(x)+cos(y)+cos(z)) + 4*cos(x)*cos(y)*cos(z), (x,-3,3), (y,-3,3), (z,-3,3), color='orangered') 

sphinx_plot(G) 

 

A gyroid:: 

 

sage: implicit_plot3d(cos(x)*sin(y) + cos(y)*sin(z) + cos(z)*sin(x), (x,-4,4), (y,-4,4), (z,-4,4), color='sandybrown') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d(cos(x)*sin(y) + cos(y)*sin(z) + cos(z)*sin(x), (x,-4,4), (y,-4,4), (z,-4,4), color='sandybrown') 

sphinx_plot(G) 

 

Tetrahedra:: 

 

sage: implicit_plot3d((x^2+y^2+z^2)^2 + 8*x*y*z - 10*(x^2+y^2+z^2) + 25, (x,-4,4), (y,-4,4), (z,-4,4), color='plum') 

Graphics3d Object 

 

.. PLOT:: 

 

x, y, z = var('x,y,z') 

G = implicit_plot3d((x**2+y**2+z**2)**2 + 8*x*y*z - 10*(x**2+y**2+z**2) + 25, (x,-4,4), (y,-4,4), (z,-4,4), color='plum') 

sphinx_plot(G) 

 

TESTS: 

 

Test a separate resolution in the X direction; this should look like a 

regular sphere:: 

 

sage: implicit_plot3d(x^2 + y^2 + z^2, (x,-2,2), (y,-2,2), (z,-2,2), plot_points=(10,40,40), contour=4) 

Graphics3d Object 

 

Test using different plot ranges in the different directions; each 

of these should generate half of a sphere. Note that we need to use 

the ``aspect_ratio`` keyword to make it look right with the unequal 

plot ranges:: 

 

sage: implicit_plot3d(x^2 + y^2 + z^2, (x,0,2), (y,-2,2), (z,-2,2), contour=4, aspect_ratio=1) 

Graphics3d Object 

 

sage: implicit_plot3d(x^2 + y^2 + z^2, (x,-2,2), (y,0,2), (z,-2,2), contour=4, aspect_ratio=1) 

Graphics3d Object 

 

sage: implicit_plot3d(x^2 + y^2 + z^2, (x,-2,2), (y,-2,2), (z,0,2), contour=4, aspect_ratio=1) 

Graphics3d Object 

 

Extra keyword arguments will be passed to show():: 

 

sage: implicit_plot3d(x^2 + y^2 + z^2, (x,-2,2), (y,-2,2), (z,-2,2), contour=4, viewer='tachyon') 

Graphics3d Object 

 

An implicit plot that doesn't include any surface in the view volume 

produces an empty plot:: 

 

sage: implicit_plot3d(x^2 + y^2 + z^2 - 5000, (x,-2,2), (y,-2,2), (z,-2,2), plot_points=6) 

Graphics3d Object 

 

Make sure that implicit_plot3d doesn't error if the function cannot 

be symbolically differentiated:: 

 

sage: implicit_plot3d(max_symbolic(x, y^2) - z, (x,-2,2), (y,-2,2), (z,-2,2), plot_points=6) 

Graphics3d Object 

""" 

# These options, related to rendering with smooth shading, are irrelevant 

# since IndexFaceSet does not support surface normals: 

# smooth: (default: False) Whether to use vertex normals to produce a 

# smooth-looking surface. False is slightly faster. 

# gradient: (default: None) If smooth is True (the default), then 

# Tachyon rendering needs vertex normals. In that case, if gradient is None 

# (the default), then we try to differentiate the function to get the 

# gradient. If that fails, then we use central differencing on the scalar 

# field. But it's also possible to specify the gradient; this must be either 

# a single python callable that takes (x,y,z) and returns a tuple (dx,dy,dz) 

# or a tuple of three callables that each take (x,y,z) and return dx, dy, dz 

# respectively. 

 

G = ImplicitSurface(f, xrange, yrange, zrange, **kwds) 

G._set_extra_kwds(kwds) 

return G