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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:43:36+00:00 2026-06-13T12:43:36+00:00

I wrote a gui where a user draws something in a (640×480) window. It

  • 0

I wrote a gui where a user draws something in a (640×480) window. It makes that drawing into a set of points stored in a Vector array. Now, how do I translate those set of points to the origin (0,0 top left corner of the window) or put it at a specified pos? The width and height of the window I want it in is also 640×480.

After that is solved, how do you scale that new set of points to a size I want?

UPDATE 1

I solved the scale issue, but not the positioning issue. The drawing is not going where I tell it to be. Code below of what I have so far.

float scaleX = (float)width/boundingPoints.width;
float scaleY = (float)height/boundingPoints.height;
for(int i = 0; i < cg_points.size()-1; i++){
    Point p1 = cg_points.get(i);
    Point p2 = cg_points.get(i+1);
    g.drawLine((int)(p1.x*scaleX) + pos.x, (int)(p1.y*scaleY) + pos.y, (int)(p2.x*scaleX) + pos.x, (int)(p2.y*scaleY) + pos.y);
}

I want the drawing to start at where pos [x, y] is. What is currently the problem is this. It does follow what pos.x and pos.y does, but it is way off and not starting at pos[x,y].

Here is a screen shot of the issue
Image of transformation issue

As you can see from the picture, the box is where the star is supposed to be. The scaling is right as you can see, just not the pos. That is because the points in the drawing may NOT start at (0,0).

Any suggestions?

Thanks!

  • 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-13T12:43:37+00:00Added an answer on June 13, 2026 at 12:43 pm

    So I solved it…YAY!!! Here is the code below in case you run into the same issue as I had.

        float scaleX = (float)width/boundingPoints.width;
        float scaleY = (float)height/boundingPoints.height;
        int bx = boundingPoints.x;
        int by = boundingPoints.y;
        for(int i = 0; i < cg_points.size()-1; i++){
                Point p1 = cg_points.get(i);
                Point p2 = cg_points.get(i+1);
                int x1 = (int) ((p1.x-bx)*scaleX);
                x1 += pos.x;
                int y1 = (int) ((p1.y-by)*scaleY);
                y1 += pos.y;
                int x2 = (int) ((p2.x-bx)*scaleX);
                x2 += pos.x;
                int y2 = (int) ((p2.y-by)*scaleY);
                y2 += pos.y;
    
                g.drawLine(x1, y1, x2, y2);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My scenario is something like: User interacts with GUI elements, audio callback function reads
I wrote a GUI-based Java program that takes 25 screenshots per second and saves
I need to write a C++ GUI such that user can make a flowchart
I'm writing a user's GUI and I want to create a method that will
I need to write a simple Java GUI application that, basically, allows the user
One of the users of a Java swing GUI program that I wrote is
So have a user interface that I wrote using MinGW QT. In the UI
Disclaimer: Cocoa newbie here. I wrote an app with a Cocoa GUI that acts
I am writing an app that requires the user to enter some data into
I'm trying wxpython for the first time. I've wrote a GUI for a python

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.