weatherman
weatherman

Reputation: 220

A line intersecting cone in mayavi

I am new to myavi, I can open example scripts in mayavi2 program or open mayavi scene from python3 script (I have kubuntu 18.04). I made simple code to illustrate the problem. By trial and error approach I can somehow display (double) cone and line in one scene. (Maybe this is not correct). But I cannot force mayavi to display what is in front and what is in back. I mean whatever angle of view I choose, line seems to be always visible. I came to the same problem with hyperbolic surface and complex 3d trajectory (plot3d()), before. Can two objects "communicate" with each other - intersections, maybe shadows? Here is my code:

#! /usr/bin/env python3
# -*- coding: utf-8 -*- 

import numpy as np
from mayavi import mlab

x, y, z = np.ogrid[-4:4:100j, -4:4:100j, -4:4:100j]
r = 0.5
# cone equation:
F = x**2 + y**2 - r*z**2

mlab.contour3d(F, contours = [0], extent=[-3,3,-3,3,-3,3], opacity=1.0)
mlab.axes()

q = np.linspace(0, 100, 20)
# points forming a line 
x1 = np.linspace(-1, -1.01, 20)
y1 = np.linspace(1, 1.01, 20)
z1 = np.linspace(-3, 3, 20)

mlab.plot3d(x1, y1, z1, q ) 

mlab.show()

line is visible allways even it should go through the coneanother view on same situation

Upvotes: 1

Views: 214

Answers (1)

user16359921
user16359921

Reputation:

I don't think you can fix this in general, but this is what I use to at least produce figures (in jupyter notebook)

import numpy as np
from tvtk.tools import visual
from mayavi import mlab
mlab.init_notebook()


x, y, z = np.ogrid[-4:4:100j, -4:4:100j, -4:4:100j]
r = 0.5
# cone equation:
F = x**2 + y**2 - r*z**2

mlab.contour3d(F, contours = [0], extent=[-3,3,-3,3,-3,3], opacity=1.0)
mlab.axes()

q = np.linspace(0, 100, 20)
# points forming a line 
x1 = np.linspace(-1, -1.01, 20)
y1 = np.linspace(1, 1.01, 20)
z1 = np.linspace(-3, 3, 20)

mlab.plot3d(x1, y1, z1, q ) 

# mlab.show()

do not use mlab.show() or view()

here is your figure corrected

Upvotes: 1

Related Questions