66298

Bad automatic Triangulation with Mayavi for coloring a surface known only by its corner

Question:

I trying to color a surface known only by its corner according to its Y value with Mayavi. Original, I I succeed in making the same thing with matplotlib (<a href="https://stackoverflow.com/questions/19836199/interpolating-a-3d-surface-known-by-its-corner-nodes-and-coloring-it-with-a-colo" rel="nofollow">here</a>) but I put back this canonical on my real data, the rendering was not sufficient and therefore I am trying now with Mayavi. I found the example from <a href="http://docs.enthought.com/mayavi/mayavi/auto/example_surface_from_irregular_data.html" rel="nofollow">Surface from irregular data example</a> which is quite helpful. However when applied to my case, reproduce here on this simple case, the triangulation gets wrong as seen on the figure below for the left surface, with two lower triangles instead of an upper and a lower triangle as for the right surface.

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/SxqZC.png" data-original="https://i.stack.imgur.com/SxqZC.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

I figure out that it came from the position of the second Y-vertices however I want to find a more general solution to 1) avoid this wrongful triangulation and 2) to have a more smooth surface by interpolating between each corner like in my <a href="https://stackoverflow.com/questions/19836199/interpolating-a-3d-surface-known-by-its-corner-nodes-and-coloring-it-with-a-colo" rel="nofollow">previous post</a> and avoid as much as possible thus the fold seen on the right surface, due to the splitting of my surface in only two triangles. Any ideas about doing this with Mayavi?

Here is the code I used to generate this simple example:

#!/usr/bin/env python #-*- coding: utf-8 -*- import numpy from mayavi import mlab X1 = numpy.array([0, 0, 1, 1]) Y1 = numpy.array([0.5, 0.75, 1, 0.5]) Z1 = numpy.array([0, 1, 0.5,0]) X2 = numpy.array([0, 0, 1, 1]) Y2 = numpy.array([-0.5, -0.45, -1, -0.5]) Z2 = numpy.array([0, 1, 0.5,0]) fig = mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0.5, 0.5, 0.5)) # Building the working triangulation # Define the points in 3D space # including color code based on Z coordinate. pts = mlab.points3d(X1, Y1, Z1, Y1, colormap='jet') # Triangulate based on X, Y with Delaunay 2D algorithm. # Save resulting triangulation. mesh = mlab.pipeline.delaunay2d(pts) # Remove the point representation from the plot pts.remove() # Draw a surface based on the triangulation surf = mlab.pipeline.surface(mesh, colormap='jet') # Building the buggus triangulation pts = mlab.points3d(X2, Y2, Z2, Y2, colormap='jet') # Triangulate based on X, Y with Delaunay 2D algorithm. # Save resulting triangulation. mesh = mlab.pipeline.delaunay2d(pts) # Remove the point representation from the plot pts.remove() # Draw a surface based on the triangulation surf = mlab.pipeline.surface(mesh, colormap='jet') # Simple plot. mlab.outline(extent=(0,1,-1,1,0,1)) mlab.axes(extent=(0,1,-1,1,0,1), nb_labels=3) mlab.show()

Answer1:

You are using different arrays compared to your matplotlib example.

matplotlib example:

z = numpy.array([0, **0.5, 1,** 0])

here:

Z1 = numpy.array([0, **1, 0.5**,0])

With the correct z array the plot looks similar to your matplotlib example, including interpolation to get a smoother color transition.

Answer2:

The function mlab.pipeline.delaunay2d computes a <strong>2D</strong> Delaunay triangulation of the set of points. That means that the triangles that are created depend only on the X and Y coordinates of the points, ignore the Z.

The two different triangulations you get are the awaited ones, as far as I have understood. Maybe there was a typo in your second data set, and that would explain why you are surprised. Did you meant the following?

X2 = numpy.array([0, 0, 1, 1]) Y2 = numpy.array([-0.5, -0.75, -1, -0.5]) Z2 = numpy.array([0, 1, 0.5,0])

The difference is the second coordinate of Y2 which is -0.75 instead of -0.45.

Recommend

  • How can I create TensorProto for TensorFlow in Java?
  • Android gradle: Sharing dependencies between product flavors
  • Visual Basic Script - KeyPress Detection?
  • Getting java.lang.RuntimeException while starting an activity
  • moq callbase for methods that do not return value (void methods)
  • How to serialize a JObject the same way as an object with Json.NET?
  • Can't get the session in java servlet
  • Camera is black on Android 4.1.2 with Unity3D and Vuforia
  • ruby: how to iterate elements in a hash efficiently
  • Embed custom control in WPF FlowDocument
  • What is are the differences between ConfigureServices and Configure in ASP .NET Core?
  • QObject::connect: Cannot connect (null)::mySignal() to (null)::mySlot()
  • Mouse clickAndHold() not working properly on Firefox Using Selenium Webdriver
  • Draggable nested inside Draggable drags both when dragging child in IE
  • Simulating argparse command line arguments input while debugging
  • The output is not displayed in its entirety [8086 assembly]
  • How to customize marker colors and shapes in scatter plot?
  • Covert RFC3339 DateTime to Date in java [duplicate]
  • How to set ringtone in Android from my activity?
  • Javascript getting the value of an input in a table [duplicate]
  • Authorization Policies/Gates for Laravel 5.3 web app consuming own API w/ Passport
  • Customize jQuery submenu positioning
  • Salesforce API: How to identify a Case from an email reference code (“[Ref: … :Ref]”)?
  • I have a problem with the Fetch API using Internet Explorer 11
  • How to add multiple legend titles (columns) in ggplot
  • Read specific column from Parquet without using Spark
  • Trigger powershell based on event log
  • Python tk scrollbar becomes inactive once text is outside the screen
  • Adding horizontal slider to QTableWidget
  • Set initial vuetify v-select value
  • git clone, upload-pack out of memory
  • Zoho API: Get the user that is making the request
  • Terminal run dalvikvm with am.jar
  • Another “Cannot make static reference…” Question
  • matrix multiplication apache pig
  • How to handle div that is created dynamically in a table
  • Update cell query for Excel ADO from Delphi
  • Make checkout phone field optional for specific countries in WooCommerce
  • Creating random wired topology for given arbitrary number of nodes on NS2
  • ReferenceError: TextEncoder is not defined