Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8899833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:57:16+00:00 2026-06-15T00:57:16+00:00

I have a vector with a min of two points in space, e.g: A

  • 0

I have a vector with a min of two points in space, e.g:

A = np.array([-1452.18133319  3285.44737438 -7075.49516676])
B = np.array([-1452.20175668  3285.29632734 -7075.49110863])

I want to find the tangent of the vector at a discrete points along the curve, g.g the beginning and end of the curve. I know how to do it in Matlab but I want to do it in Python. This is the code in Matlab:

A = [-1452.18133319  3285.44737438 -7075.49516676];
B = [-1452.20175668  3285.29632734 -7075.49110863];
points = [A; B];
distance = [0.; 0.1667];
pp = interp1(distance, points,'pchip','pp');
[breaks,coefs,l,k,d] = unmkpp(pp);
dpp = mkpp(breaks,repmat(k-1:-1:1,d*l,1).*coefs(:,1:k-1),d);
ntangent=zeros(length(distance),3);
for j=1:length(distance)
    ntangent(j,:) = ppval(dpp, distance(j));
end

%The solution would be at beginning and end:
%ntangent =
%   -0.1225   -0.9061    0.0243
%   -0.1225   -0.9061    0.0243    

Any ideas? I tried to find the solution using numpy and scipy using multiple methods, e.g.

tck, u= scipy.interpolate.splprep(data)

but none of the methods seem satisfy what I want.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:57:17+00:00Added an answer on June 15, 2026 at 12:57 am

    ok, I found the solution which is a little modification of “pv” above (note that splev works only for 1D vectors)
    One problem I was having originally with “tck, u= scipy.interpolate.splprep(data)” is that it requires a min of 4 points to work (Matlab works with two points). I was using two points. After increasing the data points, it works as i want.

    Here is the solution for completeness:

    import numpy as np
    import matplotlib.pyplot as plt
    from scipy import interpolate
    data = np.array([[-1452.18133319 , 3285.44737438, -7075.49516676],
                     [-1452.20175668 , 3285.29632734, -7075.49110863],
                     [-1452.32645025 , 3284.37412457, -7075.46633213],
                     [-1452.38226151 , 3283.96135828, -7075.45524248]])
    
    distance=np.array([0., 0.15247556, 1.0834, 1.50007])
    
    data = data.T
    tck,u = interpolate.splprep(data, u=distance, s=0)
    yderv = interpolate.splev(u,tck,der=1)
    

    and the tangents are (which matches the Matlab results if the same data is used):

    (-0.13394599723751408, -0.99063114953803189, 0.026614957159932656)
    (-0.13394598523149195, -0.99063115868512985, 0.026614950816003666)
    (-0.13394595055068903, -0.99063117647357712, 0.026614941718878599)
    (-0.13394595652952143, -0.9906311632471152, 0.026614954146007865)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two vectors of integers, and for each element of the second vector
I have a list of x,y points stored as a vector of vectors, and
I have a Max Angle and a Min Angle, and also a unit vector
I have a vector of points stored in a std::vector instance. I want to
I have two vectors with a few thousand points, but generalized here: A <-
I have created the code to perform a mapping of points from one vector
I have vector< pair<int, int>> myVec (N); I want to have all pairs initialized
in clojure i have vector [myfn1 myfn2 myfn3] how can i call functions named
I have a vector class and I defined the __mul__ method to multiply a
I have the vector d<-1:100 I want to sample k=3 times from this vector

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.