Question

In: Computer Science

2D object transformations(Use NetBeans IDE) Task: create a program that realizes 2D transformations for 2D object...

2D object transformations(Use NetBeans IDE)
Task: create a program that realizes 2D transformations for 2D object with at least three
control points:
• Movement
o The user must be able to input the movement step (in pixels)
o The movement can be controlled with keyboard cursor keys (←↑→↓)
• Scaling
o The user must be able to input the scaling parameters
o The scaling should be controlled with keyboard keys (for example "Page
Up", "Page Down")
• Rotation
o The user must be able to input the angle of rotation (in degrees)
o The user must be able to input a point, around which the object will rotate
(X, Y)
o Automatic rotation must be implemented, the user pushes a button and the
object begins to rotate around the given point (animation using timer)

Solutions

Expert Solution

Hello,

Code :

#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
int main()
{
int p1=345,q1=120,p2=190,q2=300,p3=120,q3=420,op;
int gdriver = DETECT,gmode;
initgraph(&gdriver,&gmode,”C:\TC\BGI”);
do{
cleardevice();
gotoab(1,1);
line(p1,q1,p2,q2);
line(p2,q2,p3,q3);
line(p3,q3,p1,q1);
cout<<“\n 1.Movement 2.Scaling 3.Rotation 4.Exit \n Select any option : “;
cin>>op;
switch(op)
{
case 1:
float tp,tq;
cout<<“Enter the movement value of tp & tq: “;
cin>>tp>>tq;
p1+=tp;p2+=tp;p3+=tp;
q1+=tq;q2+=tq;q3+=tq;
break;

case 2:
float sp,sq;
cout<<“Enter the scalling value of sp & sq: “;
cin>>sp>>sq;
p1*=sp;p2*=sp;p3*=sp;
q1*=sq;q2*=sq;q3*=sq;
break;

case 3:
float degree;
cout<<“Enter the angle which you want to rotate: “;
cin>>degree;
degree = degree*3.14/180;
int a,b;
a=p1;b=q1;
p1 = a*cos(degree)-b*sin(degree);
q1 = a*sin(degree)+b*cos(degree);
a=p2;b=q2;
p2 = a*cos(degree)-b*sin(degree);
q2 = a*sin(degree)+b*cos(degree);
a=p3;b=q3;
p3 = a*cos(degree)-b*sin(degree);
q3 = a*sin(degree)+b*cos(degree);
break;

case 4:
break;

default:
cout<<“The option you selected is not valid”;
}
}
while(op!=4);
closegraph();
return 0;
}


Related Solutions

Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date in multiple formats, such as MM/DD/YYYY June 14, 1992 DDD YYYY b. Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. In the third case it should receive two integer values, the first...
In C++ for netbeans. Use a 1 dimensional array object to create a 2 dimensional table...
In C++ for netbeans. Use a 1 dimensional array object to create a 2 dimensional table object. Then modify to create a triangular table. Objective -> create an array of dynamic objects of RowAray inside Table i.e. an Aggregate. See Specs RowAray.h, Table.h Then create a triangular table, i.e. Triangle. Fill each cell with random 2 digit integers. The example Table has 8 columns of RowAray objects each filled with 6 rows of random 2 digit numbers. Then create a...
Using NetBeans IDE, write a JavaFX application that allows theuser to choose insurance options. Use...
Using NetBeans IDE, write a JavaFX application that allows the user to choose insurance options. Use a ToggleGroup to allow the user to select only one of two insurance types—HMO (health maintenance organization) or PPO (preferred provider organization). Use CheckBoxes for dental insurance and vision insurance options; the user can select one option, both options, or neither option. As the user selects each option, display its name and price in a text field; the HMO costs $200 per month, the...
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the...
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the file PizzaOrder.java. Prompt the user to input the type of pizza that they want to order. In the end, you should print out the final order and price. Here is a sample output. Welcome to May and Adam’s Pizzeria Enter your first name: Amy Pizza Size(inches)     Cost         10            $10.99         12            $12.99         14            $14.99         16            $16.99 What size pizza would you...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
Create a program that reads a file of 2D coordinates and calculates the bounding box and...
Create a program that reads a file of 2D coordinates and calculates the bounding box and center of the bounding box. The bounding box is defined as the minimum area that fully encompasses all the coordinates. The center of that bounding box is calculated by taking the mean of the bounding box coordinates: ( x1+x2 2 , y1+y2 2 ). • If the input file cannot be opened, warn the user by printing "CANNOT OPEN FILE." to stdout. • Print...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
Create a Java Program to show a savings account balance. using eclipse IDE This can be...
Create a Java Program to show a savings account balance. using eclipse IDE This can be done in the main() method. Create an int variable named currentBalance and assign it the value of 0. Create an int variable named amountToSaveEachMonth. Prompt "Enter amount to save each month:" and assign the result to the int variable in step 2. Create an int variable name numberOfMonthsToSave. Prompt "Enter the number of months to save:" and store the input value into the variable...
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for...
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT