Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to draw a clothoid curve in panel, but the co ordinate values ranges from -1 to 1 due to cos and sin function. Can anyone tell me how to transform the panel size so that I could draw the clothoid curve and visualize the curve in the coordinates of x and y ranges in -1 to 1.

[Update]
Thanks for your suggestion, is there any way to increase size of pixel or co ordinates. because i want -1 to 0 and 0 to 1 to be wide visible so that i could draw curve.
[/Update]

What I have tried:

TranslateTransform and multipletransform and also used PointToClient method but its not working
Posted
Updated 26-Nov-17 22:41pm
v2
Comments
CPallini 27-Nov-17 4:43am    
"Thanks for your suggestion, is there any way to increase size of pixel or co ordinates. because i want -1 to 0 and 0 to 1 to be wide visible so that i could draw curve"
You have to increase nothing. Just apply the transformation shown in my solution: it maps the (-1,-1)-(+1,+1) square to form rectangle.

Well, it is not rocket science: you have to translate and scale your image (inverting the y-axis as well).
Supposing your paint area havs coords: top-left = {X0,Y0}, bottom-right {X1,Y1} then
xf = X0 + (x + 1) * (X1 - X0) / 2
yf = Y1 - (y + 1) * (Y1 - Y0) / 2
Where {x,y} is the computed clothoid point and {xf,yf} is its transformed cousin.
 
Share this answer
 
You can apply a scale/bias function to x and y values.
C#
// We have f() -> (x, y)
// x Є [-1, 1], y Є [-1, 1]

double x, y; // These variables have their values assigned by the function

double width = panel.Width / 2d;
double height = panel.Height / 2d;

// Scale x in the range [-width / 2, width / 2]
double newX = x * width; 
// Bias x in the range [0, width]
newX += width;

// Similarly

// Scale y in the range [-height / 2, height / 2]
double newY = y * height;
// Bias y in the range [0, height]
newY += height;

In case your panel is not square, and you do not want the resulting curve to be distorded, then you have to choose the least between both factors width and height, and use this one as the scaling factor for x and y.

Hope this helps. Kindly.
 
Share this answer
 
Thanks for your suggestion, is there any way to increase size of pixel or co ordinates. because i want -1 to 0 and 0 to 1 to be wide visible so that i could draw curve.
 
Share this answer
 
Comments
Patrice T 27-Nov-17 2:57am    
Don't use a solution to comment or ask other question.
To discuss with author if solution, use 'Have a Question or comment?' at bottom of solution. Advantage, author gets notification.
or use Improve question to update your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900