0

So i need to be able to plot a point on a graph made by my already coded cartesian coordinate system. The geometry is like: (0,0) is at the top left of the window and as it goes right, the x increases and as it goes down, the y increases so the bottom right corner would be (800, 600).

My cartesian (0,0) is actually on the point (400, 300) and that's where I want my graphs to be aligned to.

My code for getting input, converting it to an expression and graphing these points using small rectangular dots is

expression = input("Enter a mathematical 
for x in range(0, 800):
    y = eval(expression)
    rect(x, y, 2, 2)

My problem is: the code needs to be able to read and graph all normal mathematical expressions properly such as x, x^2, x^3, etc., but on my drawn cartesian plane, the values are actually all positives due to the window's weird quadrant system created by the graphics library.

I'm not getting the correct plotting when my program starts to plot out and map all these coordinates.

Could someone shed some light on what im supposed to do in terms of actually converting these graphics coordinates to match my cartesian plane coordinates?

NOTE every 30 graphics units = 1 tick unit of my cartesian plane.

1
  • I don't understand, are you saying you don't know how to shift the output to treat (400,300) as (0,0)? Commented Oct 20, 2015 at 8:25

1 Answer 1

1

if your problem is what i think it is, try the following code.

expression = input("Enter a mathematical 
for x in range(0, 800):
    x_val = x-400
    y_val = eval(expression(x_val))
    y = -y_val+300
    rect(x, y, 2, 2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.