Python - How to get z value from given x, y after surface discrete 3D points (x,y,z)












0















I am newbie at Python. I am using a block code to draw the surface from discrete 3D points as a block code below:



#!/usr/bin/python3

import sys
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from scipy import array, newaxis

DATA = array([
[-0.807237702464, 0.904373229492, 111.428744443],
[-0.802470821517, 0.832159465335, 98.572957317],
[-0.801052795982, 0.744231916692, 86.485869328],
[-0.802505546206, 0.642324228721, 75.279804677],
[-0.804158144115, 0.52882485495, 65.112895758],
[-0.806418040943, 0.405733109371, 56.1627277595],
[-0.808515314192, 0.275100227689, 48.508994388],
[-0.809879521648, 0.139140394575, 42.1027499025],
[-0.810645106092, -7.48279012695e-06, 36.8668106345],
[-0.810676720161, -0.139773175337, 32.714580273],
[-0.811308686707, -0.277276065449, 29.5977405865],
[-0.812331692291, -0.40975978382, 27.6210856615],
[-0.816075037319, -0.535615685086, 27.2420699235],
[-0.823691366944, -0.654350489595, 29.1823292975],
[-0.836688691603, -0.765630198427, 34.2275056775],
[-0.854984518665, -0.86845932028, 43.029581434],
[-0.879261949054, -0.961799684483, 55.9594146815],
[-0.740499820944, 0.901631050387, 97.0261463995],
[-0.735011699497, 0.82881933383, 84.971061395],
[-0.733021568161, 0.740454485354, 73.733621269],
[-0.732821755233, 0.638770044767, 63.3815970475],
[-0.733876941678, 0.525818698874, 54.0655910105],
[-0.735055978521, 0.403303715698, 45.90859502],
[-0.736448900325, 0.273425879041, 38.935709456],
[-0.737556181137, 0.13826504904, 33.096106049],
[-0.738278724065, -9.73058423274e-06, 28.359664343],
[-0.738507612286, -0.138781586244, 24.627237837],
[-0.738539663773, -0.275090412979, 21.857410904],
[-0.739099040189, -0.406068448513, 20.1110519655],
[-0.741152200369, -0.529726022182, 19.7019157715],
])

Xs = DATA[:,0]
Ys = DATA[:,1]
Zs = DATA[:,2]

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

surf = ax.plot_trisurf(Xs, Ys, Zs, cmap=cm.jet, linewidth=0)
fig.colorbar(surf)

ax.xaxis.set_major_locator(MaxNLocator(5))
ax.yaxis.set_major_locator(MaxNLocator(6))
ax.zaxis.set_major_locator(MaxNLocator(5))

fig.tight_layout()
plt.show()


Now I want to get Z value from any X and Y like z = f(x,y) but I don't know how can i do it.
Anyone have solution to help me.



Thank you so much.










share|improve this question




















  • 1





    Are your points unique? in other words, is your surface/function guaranteed to not have 2 different Z coordinates with the same X and Y combination?

    – robotHamster
    Nov 14 '18 at 8:52











  • Do you want to get the z value at an exact point, or do you want to get the nearest neighbor z value?

    – Nils Werner
    Nov 15 '18 at 9:40
















0















I am newbie at Python. I am using a block code to draw the surface from discrete 3D points as a block code below:



#!/usr/bin/python3

import sys
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from scipy import array, newaxis

DATA = array([
[-0.807237702464, 0.904373229492, 111.428744443],
[-0.802470821517, 0.832159465335, 98.572957317],
[-0.801052795982, 0.744231916692, 86.485869328],
[-0.802505546206, 0.642324228721, 75.279804677],
[-0.804158144115, 0.52882485495, 65.112895758],
[-0.806418040943, 0.405733109371, 56.1627277595],
[-0.808515314192, 0.275100227689, 48.508994388],
[-0.809879521648, 0.139140394575, 42.1027499025],
[-0.810645106092, -7.48279012695e-06, 36.8668106345],
[-0.810676720161, -0.139773175337, 32.714580273],
[-0.811308686707, -0.277276065449, 29.5977405865],
[-0.812331692291, -0.40975978382, 27.6210856615],
[-0.816075037319, -0.535615685086, 27.2420699235],
[-0.823691366944, -0.654350489595, 29.1823292975],
[-0.836688691603, -0.765630198427, 34.2275056775],
[-0.854984518665, -0.86845932028, 43.029581434],
[-0.879261949054, -0.961799684483, 55.9594146815],
[-0.740499820944, 0.901631050387, 97.0261463995],
[-0.735011699497, 0.82881933383, 84.971061395],
[-0.733021568161, 0.740454485354, 73.733621269],
[-0.732821755233, 0.638770044767, 63.3815970475],
[-0.733876941678, 0.525818698874, 54.0655910105],
[-0.735055978521, 0.403303715698, 45.90859502],
[-0.736448900325, 0.273425879041, 38.935709456],
[-0.737556181137, 0.13826504904, 33.096106049],
[-0.738278724065, -9.73058423274e-06, 28.359664343],
[-0.738507612286, -0.138781586244, 24.627237837],
[-0.738539663773, -0.275090412979, 21.857410904],
[-0.739099040189, -0.406068448513, 20.1110519655],
[-0.741152200369, -0.529726022182, 19.7019157715],
])

Xs = DATA[:,0]
Ys = DATA[:,1]
Zs = DATA[:,2]

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

surf = ax.plot_trisurf(Xs, Ys, Zs, cmap=cm.jet, linewidth=0)
fig.colorbar(surf)

ax.xaxis.set_major_locator(MaxNLocator(5))
ax.yaxis.set_major_locator(MaxNLocator(6))
ax.zaxis.set_major_locator(MaxNLocator(5))

fig.tight_layout()
plt.show()


Now I want to get Z value from any X and Y like z = f(x,y) but I don't know how can i do it.
Anyone have solution to help me.



Thank you so much.










share|improve this question




















  • 1





    Are your points unique? in other words, is your surface/function guaranteed to not have 2 different Z coordinates with the same X and Y combination?

    – robotHamster
    Nov 14 '18 at 8:52











  • Do you want to get the z value at an exact point, or do you want to get the nearest neighbor z value?

    – Nils Werner
    Nov 15 '18 at 9:40














0












0








0








I am newbie at Python. I am using a block code to draw the surface from discrete 3D points as a block code below:



#!/usr/bin/python3

import sys
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from scipy import array, newaxis

DATA = array([
[-0.807237702464, 0.904373229492, 111.428744443],
[-0.802470821517, 0.832159465335, 98.572957317],
[-0.801052795982, 0.744231916692, 86.485869328],
[-0.802505546206, 0.642324228721, 75.279804677],
[-0.804158144115, 0.52882485495, 65.112895758],
[-0.806418040943, 0.405733109371, 56.1627277595],
[-0.808515314192, 0.275100227689, 48.508994388],
[-0.809879521648, 0.139140394575, 42.1027499025],
[-0.810645106092, -7.48279012695e-06, 36.8668106345],
[-0.810676720161, -0.139773175337, 32.714580273],
[-0.811308686707, -0.277276065449, 29.5977405865],
[-0.812331692291, -0.40975978382, 27.6210856615],
[-0.816075037319, -0.535615685086, 27.2420699235],
[-0.823691366944, -0.654350489595, 29.1823292975],
[-0.836688691603, -0.765630198427, 34.2275056775],
[-0.854984518665, -0.86845932028, 43.029581434],
[-0.879261949054, -0.961799684483, 55.9594146815],
[-0.740499820944, 0.901631050387, 97.0261463995],
[-0.735011699497, 0.82881933383, 84.971061395],
[-0.733021568161, 0.740454485354, 73.733621269],
[-0.732821755233, 0.638770044767, 63.3815970475],
[-0.733876941678, 0.525818698874, 54.0655910105],
[-0.735055978521, 0.403303715698, 45.90859502],
[-0.736448900325, 0.273425879041, 38.935709456],
[-0.737556181137, 0.13826504904, 33.096106049],
[-0.738278724065, -9.73058423274e-06, 28.359664343],
[-0.738507612286, -0.138781586244, 24.627237837],
[-0.738539663773, -0.275090412979, 21.857410904],
[-0.739099040189, -0.406068448513, 20.1110519655],
[-0.741152200369, -0.529726022182, 19.7019157715],
])

Xs = DATA[:,0]
Ys = DATA[:,1]
Zs = DATA[:,2]

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

surf = ax.plot_trisurf(Xs, Ys, Zs, cmap=cm.jet, linewidth=0)
fig.colorbar(surf)

ax.xaxis.set_major_locator(MaxNLocator(5))
ax.yaxis.set_major_locator(MaxNLocator(6))
ax.zaxis.set_major_locator(MaxNLocator(5))

fig.tight_layout()
plt.show()


Now I want to get Z value from any X and Y like z = f(x,y) but I don't know how can i do it.
Anyone have solution to help me.



Thank you so much.










share|improve this question
















I am newbie at Python. I am using a block code to draw the surface from discrete 3D points as a block code below:



#!/usr/bin/python3

import sys
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from scipy import array, newaxis

DATA = array([
[-0.807237702464, 0.904373229492, 111.428744443],
[-0.802470821517, 0.832159465335, 98.572957317],
[-0.801052795982, 0.744231916692, 86.485869328],
[-0.802505546206, 0.642324228721, 75.279804677],
[-0.804158144115, 0.52882485495, 65.112895758],
[-0.806418040943, 0.405733109371, 56.1627277595],
[-0.808515314192, 0.275100227689, 48.508994388],
[-0.809879521648, 0.139140394575, 42.1027499025],
[-0.810645106092, -7.48279012695e-06, 36.8668106345],
[-0.810676720161, -0.139773175337, 32.714580273],
[-0.811308686707, -0.277276065449, 29.5977405865],
[-0.812331692291, -0.40975978382, 27.6210856615],
[-0.816075037319, -0.535615685086, 27.2420699235],
[-0.823691366944, -0.654350489595, 29.1823292975],
[-0.836688691603, -0.765630198427, 34.2275056775],
[-0.854984518665, -0.86845932028, 43.029581434],
[-0.879261949054, -0.961799684483, 55.9594146815],
[-0.740499820944, 0.901631050387, 97.0261463995],
[-0.735011699497, 0.82881933383, 84.971061395],
[-0.733021568161, 0.740454485354, 73.733621269],
[-0.732821755233, 0.638770044767, 63.3815970475],
[-0.733876941678, 0.525818698874, 54.0655910105],
[-0.735055978521, 0.403303715698, 45.90859502],
[-0.736448900325, 0.273425879041, 38.935709456],
[-0.737556181137, 0.13826504904, 33.096106049],
[-0.738278724065, -9.73058423274e-06, 28.359664343],
[-0.738507612286, -0.138781586244, 24.627237837],
[-0.738539663773, -0.275090412979, 21.857410904],
[-0.739099040189, -0.406068448513, 20.1110519655],
[-0.741152200369, -0.529726022182, 19.7019157715],
])

Xs = DATA[:,0]
Ys = DATA[:,1]
Zs = DATA[:,2]

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

surf = ax.plot_trisurf(Xs, Ys, Zs, cmap=cm.jet, linewidth=0)
fig.colorbar(surf)

ax.xaxis.set_major_locator(MaxNLocator(5))
ax.yaxis.set_major_locator(MaxNLocator(6))
ax.zaxis.set_major_locator(MaxNLocator(5))

fig.tight_layout()
plt.show()


Now I want to get Z value from any X and Y like z = f(x,y) but I don't know how can i do it.
Anyone have solution to help me.



Thank you so much.







python matplotlib






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 12:57







Tan Duong

















asked Nov 14 '18 at 8:46









Tan DuongTan Duong

42




42








  • 1





    Are your points unique? in other words, is your surface/function guaranteed to not have 2 different Z coordinates with the same X and Y combination?

    – robotHamster
    Nov 14 '18 at 8:52











  • Do you want to get the z value at an exact point, or do you want to get the nearest neighbor z value?

    – Nils Werner
    Nov 15 '18 at 9:40














  • 1





    Are your points unique? in other words, is your surface/function guaranteed to not have 2 different Z coordinates with the same X and Y combination?

    – robotHamster
    Nov 14 '18 at 8:52











  • Do you want to get the z value at an exact point, or do you want to get the nearest neighbor z value?

    – Nils Werner
    Nov 15 '18 at 9:40








1




1





Are your points unique? in other words, is your surface/function guaranteed to not have 2 different Z coordinates with the same X and Y combination?

– robotHamster
Nov 14 '18 at 8:52





Are your points unique? in other words, is your surface/function guaranteed to not have 2 different Z coordinates with the same X and Y combination?

– robotHamster
Nov 14 '18 at 8:52













Do you want to get the z value at an exact point, or do you want to get the nearest neighbor z value?

– Nils Werner
Nov 15 '18 at 9:40





Do you want to get the z value at an exact point, or do you want to get the nearest neighbor z value?

– Nils Werner
Nov 15 '18 at 9:40












2 Answers
2






active

oldest

votes


















0














This is a simple numpy array comparison and indexing problem. For a given pair of x, y



xy = numpy.array([-0.802470821517, 0.832159465335])


we can compare all rows to this at once, using



numpy.isclose(DATA[:, :2], xy)
# array([[False, False],
# [ True, True],
# [False, False],
# ....
# [False, False],
# [False, False]])


This will give us two boolean values per row, one for x and one for y. We are only interested in rows where both are True, so



numpy.all(numpy.isclose(DATA[:, :2], xy), axis=1)
# array([False, True, False, ..., False, False, False, False])


The result we can then use to index DATA again, and extract z like



DATA[numpy.all(numpy.isclose(DATA[:, :2], xy), axis=1), -1]
# array([98.57295732])





share|improve this answer
























  • Thank Nils for your answer. However, in case I want to get z value for a given pair of (x = -0.8, y = -0.5) your solution doesn't work. After linearize the discrete 3D point, I want to get z value in different pair of (x,y) in given DATA. Do you have any solution else for that ? Thank you

    – Tan Duong
    Nov 14 '18 at 13:06






  • 1





    Well -0.8, -0.5 don't exist in your x, y values, what do you expect?

    – Nils Werner
    Nov 15 '18 at 9:40



















0














If you want to to turn this array of points into a continuous function with input x,y and output z, you need to describe it with a model. A model allows for interpolation of points.



I assume this array of points describes a surface plot, but plotting it is unnecessary.



A surface plot looks like this (I can only provide the link):
surface plot



Each quadrilateral in the surface plot is defined by 4 points and represents part of a plane. So, a function to describe your array would be piece wise of all the different planes which make up your surface plot.



A plane requires 3 points to define it, so create a function to go through the array selecting 3 points in order, finding the equation of the plane and then adding it to an array of equations.



Code to find equation given 3 points:



def equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3):    
a1 = x2 - x1
b1 = y2 - y1
c1 = z2 - z1
a2 = x3 - x1
b2 = y3 - y1
c2 = z3 - z1
a = b1 * c2 - b2 * c1
b = a2 * c1 - a1 * c2
c = a1 * b2 - b1 * a2
d = (- a * x1 - b * y1 - c * z1)
print "equation of plane is ",
print a, "x +",
print b, "y +",
print c, "z +",
print d, "= 0."


Then for a given x and y find which plane contains these x and y points (use code similar to nils werners answer), get the corresponding equation and use that function to get the z coordinate.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296122%2fpython-how-to-get-z-value-from-given-x-y-after-surface-discrete-3d-points-x%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This is a simple numpy array comparison and indexing problem. For a given pair of x, y



    xy = numpy.array([-0.802470821517, 0.832159465335])


    we can compare all rows to this at once, using



    numpy.isclose(DATA[:, :2], xy)
    # array([[False, False],
    # [ True, True],
    # [False, False],
    # ....
    # [False, False],
    # [False, False]])


    This will give us two boolean values per row, one for x and one for y. We are only interested in rows where both are True, so



    numpy.all(numpy.isclose(DATA[:, :2], xy), axis=1)
    # array([False, True, False, ..., False, False, False, False])


    The result we can then use to index DATA again, and extract z like



    DATA[numpy.all(numpy.isclose(DATA[:, :2], xy), axis=1), -1]
    # array([98.57295732])





    share|improve this answer
























    • Thank Nils for your answer. However, in case I want to get z value for a given pair of (x = -0.8, y = -0.5) your solution doesn't work. After linearize the discrete 3D point, I want to get z value in different pair of (x,y) in given DATA. Do you have any solution else for that ? Thank you

      – Tan Duong
      Nov 14 '18 at 13:06






    • 1





      Well -0.8, -0.5 don't exist in your x, y values, what do you expect?

      – Nils Werner
      Nov 15 '18 at 9:40
















    0














    This is a simple numpy array comparison and indexing problem. For a given pair of x, y



    xy = numpy.array([-0.802470821517, 0.832159465335])


    we can compare all rows to this at once, using



    numpy.isclose(DATA[:, :2], xy)
    # array([[False, False],
    # [ True, True],
    # [False, False],
    # ....
    # [False, False],
    # [False, False]])


    This will give us two boolean values per row, one for x and one for y. We are only interested in rows where both are True, so



    numpy.all(numpy.isclose(DATA[:, :2], xy), axis=1)
    # array([False, True, False, ..., False, False, False, False])


    The result we can then use to index DATA again, and extract z like



    DATA[numpy.all(numpy.isclose(DATA[:, :2], xy), axis=1), -1]
    # array([98.57295732])





    share|improve this answer
























    • Thank Nils for your answer. However, in case I want to get z value for a given pair of (x = -0.8, y = -0.5) your solution doesn't work. After linearize the discrete 3D point, I want to get z value in different pair of (x,y) in given DATA. Do you have any solution else for that ? Thank you

      – Tan Duong
      Nov 14 '18 at 13:06






    • 1





      Well -0.8, -0.5 don't exist in your x, y values, what do you expect?

      – Nils Werner
      Nov 15 '18 at 9:40














    0












    0








    0







    This is a simple numpy array comparison and indexing problem. For a given pair of x, y



    xy = numpy.array([-0.802470821517, 0.832159465335])


    we can compare all rows to this at once, using



    numpy.isclose(DATA[:, :2], xy)
    # array([[False, False],
    # [ True, True],
    # [False, False],
    # ....
    # [False, False],
    # [False, False]])


    This will give us two boolean values per row, one for x and one for y. We are only interested in rows where both are True, so



    numpy.all(numpy.isclose(DATA[:, :2], xy), axis=1)
    # array([False, True, False, ..., False, False, False, False])


    The result we can then use to index DATA again, and extract z like



    DATA[numpy.all(numpy.isclose(DATA[:, :2], xy), axis=1), -1]
    # array([98.57295732])





    share|improve this answer













    This is a simple numpy array comparison and indexing problem. For a given pair of x, y



    xy = numpy.array([-0.802470821517, 0.832159465335])


    we can compare all rows to this at once, using



    numpy.isclose(DATA[:, :2], xy)
    # array([[False, False],
    # [ True, True],
    # [False, False],
    # ....
    # [False, False],
    # [False, False]])


    This will give us two boolean values per row, one for x and one for y. We are only interested in rows where both are True, so



    numpy.all(numpy.isclose(DATA[:, :2], xy), axis=1)
    # array([False, True, False, ..., False, False, False, False])


    The result we can then use to index DATA again, and extract z like



    DATA[numpy.all(numpy.isclose(DATA[:, :2], xy), axis=1), -1]
    # array([98.57295732])






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 14 '18 at 9:07









    Nils WernerNils Werner

    17.8k14161




    17.8k14161













    • Thank Nils for your answer. However, in case I want to get z value for a given pair of (x = -0.8, y = -0.5) your solution doesn't work. After linearize the discrete 3D point, I want to get z value in different pair of (x,y) in given DATA. Do you have any solution else for that ? Thank you

      – Tan Duong
      Nov 14 '18 at 13:06






    • 1





      Well -0.8, -0.5 don't exist in your x, y values, what do you expect?

      – Nils Werner
      Nov 15 '18 at 9:40



















    • Thank Nils for your answer. However, in case I want to get z value for a given pair of (x = -0.8, y = -0.5) your solution doesn't work. After linearize the discrete 3D point, I want to get z value in different pair of (x,y) in given DATA. Do you have any solution else for that ? Thank you

      – Tan Duong
      Nov 14 '18 at 13:06






    • 1





      Well -0.8, -0.5 don't exist in your x, y values, what do you expect?

      – Nils Werner
      Nov 15 '18 at 9:40

















    Thank Nils for your answer. However, in case I want to get z value for a given pair of (x = -0.8, y = -0.5) your solution doesn't work. After linearize the discrete 3D point, I want to get z value in different pair of (x,y) in given DATA. Do you have any solution else for that ? Thank you

    – Tan Duong
    Nov 14 '18 at 13:06





    Thank Nils for your answer. However, in case I want to get z value for a given pair of (x = -0.8, y = -0.5) your solution doesn't work. After linearize the discrete 3D point, I want to get z value in different pair of (x,y) in given DATA. Do you have any solution else for that ? Thank you

    – Tan Duong
    Nov 14 '18 at 13:06




    1




    1





    Well -0.8, -0.5 don't exist in your x, y values, what do you expect?

    – Nils Werner
    Nov 15 '18 at 9:40





    Well -0.8, -0.5 don't exist in your x, y values, what do you expect?

    – Nils Werner
    Nov 15 '18 at 9:40













    0














    If you want to to turn this array of points into a continuous function with input x,y and output z, you need to describe it with a model. A model allows for interpolation of points.



    I assume this array of points describes a surface plot, but plotting it is unnecessary.



    A surface plot looks like this (I can only provide the link):
    surface plot



    Each quadrilateral in the surface plot is defined by 4 points and represents part of a plane. So, a function to describe your array would be piece wise of all the different planes which make up your surface plot.



    A plane requires 3 points to define it, so create a function to go through the array selecting 3 points in order, finding the equation of the plane and then adding it to an array of equations.



    Code to find equation given 3 points:



    def equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3):    
    a1 = x2 - x1
    b1 = y2 - y1
    c1 = z2 - z1
    a2 = x3 - x1
    b2 = y3 - y1
    c2 = z3 - z1
    a = b1 * c2 - b2 * c1
    b = a2 * c1 - a1 * c2
    c = a1 * b2 - b1 * a2
    d = (- a * x1 - b * y1 - c * z1)
    print "equation of plane is ",
    print a, "x +",
    print b, "y +",
    print c, "z +",
    print d, "= 0."


    Then for a given x and y find which plane contains these x and y points (use code similar to nils werners answer), get the corresponding equation and use that function to get the z coordinate.






    share|improve this answer




























      0














      If you want to to turn this array of points into a continuous function with input x,y and output z, you need to describe it with a model. A model allows for interpolation of points.



      I assume this array of points describes a surface plot, but plotting it is unnecessary.



      A surface plot looks like this (I can only provide the link):
      surface plot



      Each quadrilateral in the surface plot is defined by 4 points and represents part of a plane. So, a function to describe your array would be piece wise of all the different planes which make up your surface plot.



      A plane requires 3 points to define it, so create a function to go through the array selecting 3 points in order, finding the equation of the plane and then adding it to an array of equations.



      Code to find equation given 3 points:



      def equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3):    
      a1 = x2 - x1
      b1 = y2 - y1
      c1 = z2 - z1
      a2 = x3 - x1
      b2 = y3 - y1
      c2 = z3 - z1
      a = b1 * c2 - b2 * c1
      b = a2 * c1 - a1 * c2
      c = a1 * b2 - b1 * a2
      d = (- a * x1 - b * y1 - c * z1)
      print "equation of plane is ",
      print a, "x +",
      print b, "y +",
      print c, "z +",
      print d, "= 0."


      Then for a given x and y find which plane contains these x and y points (use code similar to nils werners answer), get the corresponding equation and use that function to get the z coordinate.






      share|improve this answer


























        0












        0








        0







        If you want to to turn this array of points into a continuous function with input x,y and output z, you need to describe it with a model. A model allows for interpolation of points.



        I assume this array of points describes a surface plot, but plotting it is unnecessary.



        A surface plot looks like this (I can only provide the link):
        surface plot



        Each quadrilateral in the surface plot is defined by 4 points and represents part of a plane. So, a function to describe your array would be piece wise of all the different planes which make up your surface plot.



        A plane requires 3 points to define it, so create a function to go through the array selecting 3 points in order, finding the equation of the plane and then adding it to an array of equations.



        Code to find equation given 3 points:



        def equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3):    
        a1 = x2 - x1
        b1 = y2 - y1
        c1 = z2 - z1
        a2 = x3 - x1
        b2 = y3 - y1
        c2 = z3 - z1
        a = b1 * c2 - b2 * c1
        b = a2 * c1 - a1 * c2
        c = a1 * b2 - b1 * a2
        d = (- a * x1 - b * y1 - c * z1)
        print "equation of plane is ",
        print a, "x +",
        print b, "y +",
        print c, "z +",
        print d, "= 0."


        Then for a given x and y find which plane contains these x and y points (use code similar to nils werners answer), get the corresponding equation and use that function to get the z coordinate.






        share|improve this answer













        If you want to to turn this array of points into a continuous function with input x,y and output z, you need to describe it with a model. A model allows for interpolation of points.



        I assume this array of points describes a surface plot, but plotting it is unnecessary.



        A surface plot looks like this (I can only provide the link):
        surface plot



        Each quadrilateral in the surface plot is defined by 4 points and represents part of a plane. So, a function to describe your array would be piece wise of all the different planes which make up your surface plot.



        A plane requires 3 points to define it, so create a function to go through the array selecting 3 points in order, finding the equation of the plane and then adding it to an array of equations.



        Code to find equation given 3 points:



        def equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3):    
        a1 = x2 - x1
        b1 = y2 - y1
        c1 = z2 - z1
        a2 = x3 - x1
        b2 = y3 - y1
        c2 = z3 - z1
        a = b1 * c2 - b2 * c1
        b = a2 * c1 - a1 * c2
        c = a1 * b2 - b1 * a2
        d = (- a * x1 - b * y1 - c * z1)
        print "equation of plane is ",
        print a, "x +",
        print b, "y +",
        print c, "z +",
        print d, "= 0."


        Then for a given x and y find which plane contains these x and y points (use code similar to nils werners answer), get the corresponding equation and use that function to get the z coordinate.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 13 at 10:59









        Joe ClintonJoe Clinton

        33




        33






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296122%2fpython-how-to-get-z-value-from-given-x-y-after-surface-discrete-3d-points-x%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues