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

  • SEARCH
  • Home
  • 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 682675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:37:22+00:00 2026-05-14T01:37:22+00:00

I have a triangle in (u,v) coordinates in an image. I would like to

  • 0

I have a triangle in (u,v) coordinates in an image. I would like to draw this triangle at 3D coordinates (X,Y,Z) texture-mapped with the triangle in the image.

Here, u,v,X,Y,Z are all vectors with three elements representing the three corners of the triangle.

I have a very ugly, slow and unsatisfactory solution in which I:

  1. extract a rectangular part of the image
  2. transform it to 3D space with the transformation defined by the three points
  3. draw it with surface
  4. finally masking out everything that is not part of the triangle with AlphaData

Surely there must be an easier way of doing this?

  • 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-05-14T01:37:22+00:00Added an answer on May 14, 2026 at 1:37 am

    I have what I think is a better solution for you involving two steps. First, it extracts a rectangular part of your image, half of which is the triangular section to be used as a texture map and half of which will be ignored. Then this texture map is applied to a 3-D surface object whose points are adjusted to render it as a triangle instead of a quadrilateral.

    For the example I will show here, I will use the following values for your various parameters, assuming you have a triangle whose points are labeled as the “origin” (triangle vertex), point “A”, and point “B” in the image space (as in the first image below):

    x = [0.1 0.9 0.8];   % [xorigin xA xB] coordinates in 3-D space
    y = [0.9 0.1 0.8];   % [yorigin yA yB] coordinates in 3-D space
    z = [0.1 0.1 0.9];   % [zorigin zA zB] coordinates in 3-D space
    origin = [150 350];  % Vertex of triangle in image space
    U = [300 -50];       % Vector from origin to point A in image space
    V = [50 -250];       % Vector from origin to point B in image space
    img = imread('peppers.png');  % Sample image for texture map
    

    Extracting the texture map via projective transformation:

    This step uses the Image Processing Toolbox functions maketform and imtransform to perform a projective transformation of the part of the image containing the triangle you want to use as a texture map. Note that since images have to be rectangular, an additional triangular section defined by points (O,B,C) has to be included.

    enter image description here

    The triangular part of the image you want will be in the lower right half of the image, while the additional triangular “filler” part will be in the upper left. Note that this additional triangle can extend outside of the image, which will cause part of it to be filled with black by default. Here’s the code to perform the projective transform illustrated above:

    A = origin+U;  % Point A
    B = origin+V;  % Point B
    C = B-U;       % Point C
    [nRows, nCols, nPages] = size(img);  % Image dimensions
    inputCorners = [origin; ...          % Corner coordinates of input space
                    A; ...
                    B; ...
                    C];
    outputCorners = [1 nRows; ...        % Corner coordinates of output space
                     nCols nRows; ...
                     nCols 1; ...
                     1 1];
    tform = maketform('projective', ...  % Make the transformation structure
                      inputCorners, ...
                      outputCorners);
    triTexture = imtransform(img,tform, 'bicubic', ...  % Transform the image
                             'xdata', [1 nCols], ...
                             'ydata', [1 nRows], ...
                             'size', [nRows nCols]);
    

    Note that this code will create a final image triTexture that is the same size as the input image img.

    Plotting the triangular texture-mapped surface:

    Plotting the surface is now quite simple, assuming you’ve ordered the values in your x,y,z variables such that the coordinates for the origin point are in the first indices, the coordinates for point A are in the second indices, and the coordinates for point B are in the third indices. You can now create new sets of 2-by-2 surface coordinates X,Y,Z that contain two copies of point B, which causes only half of the surface to be rendered (i.e. the half containing the desired triangular image as a texture map). Here’s the code to do this:

    index = [3 3; 1 2];  % Index used to create 2-by-2 surface coordinates
    X = x(index);        % x coordinates of surface
    Y = y(index);        % y coordinates of surface
    Z = z(index);        % z coordinates of surface
    hSurface = surf(X, Y, Z, triTexture, ...  % Plot texture-mapped surface
                    'FaceColor', 'texturemap', ...
                    'EdgeColor', 'none');
    axis equal            % Use equal scaling on axes
    axis([0 1 0 1 0 1]);  % Set axes limits
    xlabel('x-axis');     % x-axis label
    ylabel('y-axis');     % y-axis label
    zlabel('z-axis');     % z-axis label
    

    And here’s the resulting texture-mapped triangular surface it creates, with an inset added to show that the texture map contains the correct triangular part of the original image:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a polygon soup of triangles that I would like to construct a
I have some problems mapping a texture to a triangle strip. I think I
Say I have a square from (0,0) to (z,z). Given a triangle within this
If you have an equilateral triangle in 3D space, where all the sides are
I have a triangle drawn by a user and all the points are stored
Okay, I'm going to sound like an idiot with this one. Here goes. I've
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have a number of spherical longitude/latitude coordinates for points on a sphere that
I have an interesting problem here I've been trying to solve for the last
Based on this original idea, that many of you have probably seen before: http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/

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.