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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:38:27+00:00 2026-06-03T19:38:27+00:00

I am writing a custom control which draws polygons. I use matrix calculations to

  • 0

I am writing a custom control which draws polygons.
I use matrix calculations to scale and shear the polygons so that they fit the control.

I need to know if the mouse has been clicked inside one of the polygons, so I am using ray casting.

This all seems to work fine individually, however I am now encountering an issue with retrieving the mouse coordinates relative to the display matrix im using.

I use the following code:

// takes the graphics matrix used to draw the polygons
Matrix mx = currentMatrixTransform;            

// inverts it
mx.Invert();

// mouse position
Point[] pa = new Point[] { new Point(e.X, e.Y) };

// uses it to transform the current mouse position
mx.TransformPoints(pa);

return pa[0];

now this works for every other set of coordinates, by that I mean that one pair of mouse coordinates appears to give the correct values as if it has been through the matrix, but the one beside it gives a value as if it has not been through the matrix, below is an output of the mouse values received when moving down the control.

{X=51,Y=75}
{X=167,Y=251}
{X=52,Y=77}
{X=166,Y=254}
{X=52,Y=78}
{X=166,Y=258}
{X=52,Y=79}
{X=166,Y=261}
{X=52,Y=80}
{X=165,Y=265}
{X=52,Y=81}
{X=165,Y=268}

if it helps the matrix used to draw the polygons is

Matrix trans = new Matrix();
trans.Scale(scaleWidth, scaleHeight);            
trans.Shear(italicFactor, 0.0F, MatrixOrder.Append);
trans.Translate(offsetX, offsetY, MatrixOrder.Append);

e.Graphics.Transform = trans;
currentMatrixTransform = e.Graphics.Transform;

Thanks in advance

  • 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-03T19:38:28+00:00Added an answer on June 3, 2026 at 7:38 pm

    You are inverting your matrix each time you call it.
    Matrix is a class, meaning that by performing Invert() on mx, you are also performing it on currentMatrixTransform.

    You can either copy the matrix using Clone() and then invert the clone,
    or you can perform Invert() once again after you’ve transformed the point pa.

    A second invert example:

    // takes the graphics matrix used to draw the polygons
    Matrix mx = currentMatrixTransform;            
    
    // inverts it
    mx.Invert();
    
    // mouse position
    Point[] pa = new Point[] { new Point(e.X, e.Y) };
    
    // uses it to transform the current mouse position
    mx.TransformPoints(pa);
    
    // inverts it back
    max.Invert();
    
    return pa[0];
    

    A clone example:

    // takes the graphics matrix used to draw the polygons
    Matrix mx = currentMatrixTransform.Clone();
    
    // inverts it
    mx.Invert();
    
    // mouse position
    Point[] pa = new Point[] { new Point(e.X, e.Y) };
    
    // uses it to transform the current mouse position
    mx.TransformPoints(pa);
    
    return pa[0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a custom compound control that extends RelativeLayout. Inside this component, there is
When writing a custom ControlTemplate (XAML) for a Win 8 Metro control we need
Which approach should I prefer when it comes to writing a custom control in
I'm currently writing an custom control which has to hold child control and have
I'm writing a custom control which uses a template defined in the resources section
I'm writing a custom control which includes a text box input and an unordered
I am writing a custom Control class in C# for my main project. There're
I'm writing my first custom user control against WinRT, and I've run into a
I am writing an ASP.NET custom control. In my custom control code, I find
We're writing an application for Windows tablet PCs. I have created a custom control

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.