Having trouble with implementing the Bilinear transformation code

Interested in experimenting with the bilinear transformation of a rectangle to a quad? Check out the details here: on page 4.

The square coordinates are:

(500,900)(599,900)(599,999)(500,999)

While the quad coordinates are:

(454,945)(558,951)(598,999)(499,999)

Simply align the corresponding corners for both shapes. Then create matrices based on these values:

[1 500 900 450000][a0] [454]
[1 599 900 539100][a1]=[558]
[1 599 999 598401][a2] [598]
[1 500 999 499500][a3] [499]

[1 500 900 450000][b0] [945]
[1 599 900 539100][b1]=[951]
[1 599 999 598401][b2] [999]
[1 500 999 499500][b3] [999]

Solving for these matrices gives:

a0=-709.911845730028
a1=1.50964187327824
a2=0.709621467197225
a3=-0.000510152025303541
b0=148.305785123967 
b1=0.611570247933884 
b2=0.85154576063667 
b3=-0.000612182430364249

However, running a Python script for manual simulation results in different output. For instance, converting point (454, 945) on the quad to (500,900) on the square yields (442.90822654, 1024.0)...

X = 454
Y = 945

a0=-709.911845730028
a1=1.50964187327824
a2=0.709621467197225
a3=-0.000510152025303541


b0=148.305785123967 
b1=0.611570247933884 
b2=0.85154576063667 
b3=-0.000612182430364249

A = b2*a3 - b3*a2
C_one = (b0*a1 - b1*a0)
C = C_one + (b1*X - a1*Y)
B_one = (b0*a3 - b3*a0) + (b2*a1 - b1*a2)
B = B_one + (b3*X - a3*Y)

V = (-B + (B*B - 4*A*C)**0.5 ) / (2*A)
U = (X - a0 - a2*V) / (a1 + a3*V)

print U,V

Seeking advice on what may be causing this discrepancy.

Answer №1

After carefully understanding the linear algebra notation provided, I respectfully disagree with the values assigned to variables a and b:

sage: A = Matrix([[1,500,900,450000],[1, 599, 900, 539100],
                  [1, 599, 999 ,5984],[1, 500, 999, 499500]])
sage: v = vector([945, 951, 999, 999])
sage: w = vector([454, 558, 598, 499])
sage: a = A.solve_right(w)
sage: b = A.solve_right(v)
sage: print(a); print(N(a))
(-3435371408/7209873, 15036641/14419746, 721395/1602194, 5/582616)
(-476.481542462676, 1.04278126674353, 0.450254463566834, 8.58198195724113e-6)
sage: print(b); print(N(b))
(1029623095/2403291, 123379/2403291, 432837/801097, 3/291308)
(428.422149044789, 0.0513375200922402, 0.540305356280201, 0.0000102983783486894)
sage: 
sage: A * a
(454, 558, 598, 499)
sage: A * b
(945, 951, 999, 999)

Upon computation:

from math import sqrt

X = 454
Y = 945

a = (-476.481542462676, 1.04278126674353,
     0.450254463566834, 8.58198195724113e-6)

b = (428.422149044789, 0.0513375200922402,
     0.540305356280201, 0.0000102983783486894)

A = b[2]*a[3] - b[3]*a[2]
C_one = (b[0]*a[1] - b[1]*a[0])
C = C_one + (b[1]*X - a[1]*Y)
B_one = (b[0]*a[3] - b[3]*a[0]) + (b[2]*a[1] - b[1]*a[2])
B = B_one + (b[3]*X - a[3]*Y)
V = (-B + sqrt((pow(B,2) - 4*A*C))) / (2*A)
U = (X - a[0] - a[2]*V) / (a[1] + a[3]*V)

print( U,V )

The resulting calculation shows:

892.3074973991894 -0.0

This outcome differs from previous results; further verification is needed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are some strategies to tackle the 988 character limit in an email header?

As I attempt to send emails to a considerable number of individuals (100+), the email string gets disrupted after the 988th character, leading to an "undeliverable" error due to an unexpected newline. Being relatively new to coding, I have gathered code s ...

How to retrieve webpage data using Python's "login with Google" authentication

Is it feasible to retrieve the content of a page with a specific URL using Python 3.x? When I visit the URL in my browser, I am only given the option to "Continue with Google." After providing my Google account credentials, I am able to access the desire ...

Easily link Facebook with your Google App Engine project using Python

Looking for a streamlined and effective demonstration of integrating Facebook connect into a Google App Engine application. Currently building a web application and aiming to utilize Facebook connect as the main login method. ...

The speed of Intellij's code completion when using the dot symbol is notably sluggish in comparison to its

Recently, while working with Python in Intellij version 2020, I came across an interesting observation regarding code completion. I couldn't help but notice that regular text prompts code completions almost immediately, whereas when I press ., there ...

Tips on sorting through a JSON response for particular keywords

When utilizing an API for a software, my main goal is to extract the ID of a specific item. Below is the code I am using to make the GET request: import requests import json url = "apiurl" payload = "" headers = { 'Authorization&a ...

Ways to terminate a NodeJS child exec process?

I'm running a Python program from NodeJS using the exec function of child_process. I want to be able to terminate the process with a button click. Running this on Windows11. Below is my code snippet : var process__ = undefined; // declaring a global ...

What is the method for determining the sum of identical elements in two lists that appear at corresponding positions?

Consider the following two lists: x = [0,1,2,2,5,2,1,0,1,2] y = [0,1,3,2,1,4,1,3,1,2] In Python, how can we identify and print the elements that are common between these two lists? I attempted the following approach: for i in range(len(x)): if x[i] ...

Python: What is the best method to convert the string { apple: "1" , orange: "2" } into a dictionary?

I just got some results that look like this. { banana: '5', pineapple: '2', strawberry: '4' } It's not exactly in JSON format, but is it still feasible to convert it into a Python Dictionary? Do the keys ban ...

Ways to incorporate my python script into a different file using visual studio code

I am currently using Python with Selenium in Visual Studio Code. My goal is to import another Python class called driverScript located within the executionEngine module, specifically in the file named DriverScript. I have attempted to import it as shown be ...

A Python program designed to extract data from an Excel spreadsheet and overlay it onto an image

I have a Excel spreadsheet with data that I need to overlay onto an image with the same name as the Excel file. Any assistance would be greatly appreciated. from PIL import Image,ImageDraw,ImageFont import glob import os images=glob.glob("E:\Ima ...

Resolving the Django REST problem: Implementing additional actions with ListApiView

Working on a new project utilizing the Django REST API framework. Encountering an error when running the project locally: File "/home/asad/PycharmProjects/microshop/venv/lib/python3.8/site-packages/rest_framework/routers.py", line 153, in get_rou ...

Having trouble including Seaborn as a dependency in your Python project with Poetry?

I am currently struggling to incorporate the Seaborn dependency into my module using Poetry. Despite attempting various methods, I have not been successful thus far, leading me to believe that I might be approaching it incorrectly. Below is my current to ...

Could json.loads() be exploited for executing arbitrary code?

Does the json.loads function from Python's built-in json module pose any risk of allowing arbitrary code execution or other security vulnerabilities? I need to process JSON data from sources that may not be trustworthy. ...

"Encountered an issue while attempting to scrape data from Rotten Tomatoes website

One of my tasks is to extract information from a webpage on Rotten Tomatoes. This is the screenshot of the page Based on the image, it seems that span class= descriptor is the parent class of a class, and div class = info director contains information ab ...

What is causing a 500 internal error in Django when using Ajax?

Can someone help me troubleshoot why I keep receiving a 500 internal error when trying to execute an Ajax function? I attempted to send the response from view.py to the Ajax function in two different ways: using JsonResponse (see 'else' section i ...

Flask decorator for rendering JSON views on Google App Engine

Currently, I am attempting to create a view rendering decorator for JSON in Flask by referring to this specific code snippet: http://flask.pocoo.org/snippets/18/ My challenge lies in the necessity of serializing GAE models as JSON, which the regular jsoni ...

What is the process for parsing JSON data in a Django application?

How can I extract data from a JSON object transmitted by an android form (using the GET method) to a django python server? I have attempted this approach def post_article(sample): #sample represents the HTTP request json_data = sample.read() ...

Exploring the intricacies of Unicode and encoding within Python

After entering the following code in the python 2.7 console >>>'áíóús' '\xc3\xa1\xc3\xad\xc3\xb3\xc3\xbas' >>>u'áíóús' u'\xe1\xed\xf3\ ...

Encountering Error: ImportError when working with Google App Engine locally: Module google.cloud.bigquery not found

Just like the title suggests. I have included the following code in appengine_config.py, but it doesn't seem to be working: # appengine_config.py from google.appengine.ext import vendor # Add any libraries installed in the "lib" folder. vendor.add( ...

I am perplexed by the driver's inability to locate the element

Check out this webpage for the latest updates: I am attempting to extract data on EPS, EPS beat, GEPS, GEPS beat, and revenue from this site. List1 = driver.find_element_by_xpath("""/html/body/div[2]/div[1]/div/main/div[2]/div[3]/div[2]/sec ...