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 266757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:28:14+00:00 2026-05-11T23:28:14+00:00

Hi i am trying to create the affine transform that will allow me to

  • 0

Hi i am trying to create the affine transform that will allow me to transform a triangle into another one. What i have are the coordinates for the 2 triangles. Can you help me?

Following the answer by Adam Rosenfield i came up with this code in case anyone is bored to solve the equation himself :

public static AffineTransform createTransform(ThreePointSystem source,
            ThreePointSystem dest) {        
    double x11 = source.point1.getX();
    double x12 = source.point1.getY();
    double x21 = source.point2.getX();
    double x22 = source.point2.getY();
    double x31 = source.point3.getX();
    double x32 = source.point3.getY();
    double y11 = dest.point1.getX();
    double y12 = dest.point1.getY();
    double y21 = dest.point2.getX();
    double y22 = dest.point2.getY();
    double y31 = dest.point3.getX();
    double y32 = dest.point3.getY();

    double a1 = ((y11-y21)*(x12-x32)-(y11-y31)*(x12-x22))/
                ((x11-x21)*(x12-x32)-(x11-x31)*(x12-x22));
    double a2 = ((y11-y21)*(x11-x31)-(y11-y31)*(x11-x21))/
                ((x12-x22)*(x11-x31)-(x12-x32)*(x11-x21));
    double a3 = y11-a1*x11-a2*x12;
    double a4 = ((y12-y22)*(x12-x32)-(y12-y32)*(x12-x22))/
                ((x11-x21)*(x12-x32)-(x11-x31)*(x12-x22));
    double a5 = ((y12-y22)*(x11-x31)-(y12-y32)*(x11-x21))/
                ((x12-x22)*(x11-x31)-(x12-x32)*(x11-x21));
    double a6 = y12-a4*x11-a5*x12;
    return new AffineTransform(a1, a4, a2, a5, a3, a6);
}
  • 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-11T23:28:15+00:00Added an answer on May 11, 2026 at 11:28 pm

    I’m going to assume you’re talking about 2D here. An affine transformation matrix has 9 values in it:

        | a1 a2 a3 |
    A = | a4 a5 a6 |
        | a7 a8 a9 |
    

    There are 3 input vertices x1, x2, and x3, which when transformed should become y1, y2, y3. However, since we’re working in homogeneous coordinates, applying A to x1 doesn’t necessarily give y1 — it gives a multiple of y1. So, we also have the unknown multipliers k1, k2, and k3, with the equations:

    A*x1 = k1*y1
    A*x2 = k2*y2
    A*x3 = k3*y3
    

    Each of those is a vector, so we really have 9 equations in 12 unknowns, so the solution is going to be underconstrained. If we require that a7=0, a8=0, and a9=1, then the solution will be unique (this choice is natural, since it means if the input point is (x, y, 1), then the output point will always have homogeneous coordinate 1, so the resulting transform is just a 2×2 transform plus a translation).

    Hence, this reduces the equations to:

    a1*x11 + a2*x12 + a3 = k1*y11
    a4*x11 + a5*x12 + a6 = k1*y12
                       1 = k1
    a1*x21 + a2*x22 + a3 = k2*y21
    a4*x21 + a5*x22 + a6 = k2*y22
                       1 = k2
    a1*x31 + a2*x32 + a3 = k3*y31
    a4*x31 + a5*x32 + a6 = k3*y32
                       1 = k3
    

    So, k1 = k2 = k3 = 1. Plugging these in and converting to matrix form yields:

    | x11 x12   1   0   0   0 |   | a1 |   | y11 |
    | x21 x22   1   0   0   0 |   | a2 |   | y21 |
    | x31 x32   1   0   0   0 | * | a3 | = | y31 |
    |   0   0   0 x11 x12   1 |   | a4 |   | y12 |
    |   0   0   0 x21 x22   1 |   | a5 |   | y22 |
    |   0   0   0 x31 x32   1 |   | a6 |   | y32 |
    

    Solving this 6×6 system of equations yields you your affine transformation matrix A. It will have a unique solution if and only if the 3 points of your source triangle are not collinear.

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

Sidebar

Related Questions

I am trying create a data.frame from which to create a graph. I have
Trying to create an Oracle trigger that runs after a table is updated in
Trying to create a request only to have a runtime error thrown. Method initiating
Problem: Trying to create a Mix that is applied to the AVPlayerItem, but it
Trying to create an array of structs (new to C), but I am getting
Trying to create an android app with Facebook integration, I've gotten to the part
Im trying to create a table with this code: CREATE TABLE IF NOT EXISTS
im trying to create a mp3 player for windows phone 7...how do i create
Am trying to create a 3d line control using lineshape control in vb2008, and
im trying to create a basic profile for someone and am practicing using the

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.