0

I have 3d points in file.I read them :

def points_to_array(pathIn):
    pointArray = []
    point = []
    in_file = open(pathIn, 'r')
    for line in in_file.readlines():
        split_line = line.strip('\n').split(' ')
        for i in range(0, 3):
            point.append(float(split_line[i]))
        pointArray.append(point)
        point = []
    return pointArray

And display them this way

import pyvista as pv
plotter = pv.Plotter(window_size=(1600, 1100))
points = points_to_array("C:\points.txt")
npPointArray = np.array(points)
plotter.add_points(npPointArray, color = 'r')

I want to add a line between some points (i.e from point to point as they appear in the file) Can I do this? how?

YAKOVM
  • 9,805
  • 31
  • 116
  • 217

1 Answers1

2

Here's a simple example that should help. What this example does is create some lines as defined by the lines array using the vtk format of describing cells (basically, the number of points per cell, and then the cell connectivity). In this example, we're just going to create two simple lines, but you could make more, and include as many points per line as you wish.

import numpy as np
import pyvista as pv


points = np.array([[0, 0, 0],
                   [1, 0, 0],
                   [1, 1, 0],
                   [0, 1, 0]])

lines = np.hstack(([2, 0, 1],
                   [2, 1, 2]))

pdata = pv.PolyData(points)
pdata.lines = lines

pl = pv.Plotter()
pl.add_mesh(pdata)
pl.camera_position = 'xy'
pl.add_point_labels(points, range(4), font_size=20)
pl.show()

pyvista plot

Alex Kaszynski
  • 1,817
  • 2
  • 17
  • 17