![]() |
#5
|
|||
|
|||
So I transferred some Matlab code into Python and then did a 3D plot, see below code.
import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt def get_sphere_line(center, pt_1, pt_2): """ Get the coordinates to craft an arc """ x0, y0, z0 = center x1, y1, z1 = pt_1 x2, y2, z2 = pt_2 v1 = [x1 - x0, y1 - y0, z1 - z0] # Vector from center to 1st point r = np.linalg.norm(v1) # The radius v2 = [x2 - x0, y2 - y0, z2 - z0] # Vector from center to 2nd point v3 = np.cross(np.cross(v1, v2), v1) # v3 lies in plane of v1 & v2 and is orthog. to v1 v3 = r*v3/np.linalg.norm(v3) # Make v3 of length r # Let t range through the inner angle between v1 and v2 t = np.linspace(0, np.arctan2(np.linalg.norm(np.cross(v1, v2)), np.dot(v1, v2)), num=100)[:, np.newaxis].T v = np.array(v1)[:, np.newaxis]*np.cos(t) + np.array(v3)[:, np.newaxis]*np.sin(t) # v traces great circle path, relative to center xs, ys, zs = v[0, :] + x0, v[1, :] + y0, v[2, :] + z0 return xs, ys, zs xs, ys, zs = get_sphere_line([2.85, 0.001, 0.238], [1.722, .001, .46], [3.94, 0.001, 0.026]) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot(xs, ys, zs) plt.show() The below code is how I am trying to implement it in Vizard, but it isn't working properly. vs = get_sphere_line([2.85, 0.001, 0.238], [1.722, .001, .46], [3.94, .001, 0.026]) viz.startLayer(viz.LINE_STRIP) viz.lineWidth(5) viz.vertexColor(viz.YELLOW) for v in vs: viz.vertex([v[0], v[1], v[2]]) viz.endLayer() |
Tags |
arc, great circle, vizshape |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Why I need two points for viz.startlayer(viz.POINTS) | jincheker | Vizard | 1 | 01-28-2011 08:46 AM |
avatar walking over a sequence of points | IGoudt | Vizard | 1 | 10-16-2009 11:22 AM |
Create Button or Text | Chrissy2009 | Vizard | 1 | 07-15-2009 05:34 PM |
Draw Line between Points | Chrissy2009 | Vizard | 2 | 05-13-2009 04:42 AM |
How to create a sky? | guxmy01 | Vizard | 1 | 05-28-2008 12:07 PM |