Help with Angle Rotations pls..
-
hi guys, am having problem with angle rotations.. i already have the formula, double fangle; double m_iAngle; m_iAngle = 45; POINT centerPt; centerPt.x = m_nCarX + 161; // which s is the x origin centerPt.y = y + 52; // which s is the y origin fangle = m_iAngle / 180. * 3.1415926; float OrX = (float)(centerPt.x - cos(fangle)*centerPt.x + sin(fangle)*centerPt.y); float OrY = (float)(centerPt.y - cos(fangle)*centerPt.y - sin(fangle)*centerPt.x); //tyre spoke dc.SelectStockObject(GRAY_BRUSH); dc.SelectObject(m_penTyreSpoke); for(int count = 0, count < 4, count++){ //spoke1 dc.MoveTo(m_nCarX + 161, y + 52); dc.LineTo(m_nCarX + 161, y + 41); } //see image here: http://h1.ripway.com/lgmanuel/Imgs/car.png[^] as you see in the image. the car's tire has only one spoke. am trying to loop the code to have 4 (four) spokes on my rim by bending the angle 90 DEGREES.. adding a 90 DEGREES on LOOP... //should look like this images bellow: http://h1.ripway.com/lgmanuel/Imgs/car-with-rim-spoke.png[^] help guys.. check the project bellow.. thanks ahead.. http://h1.ripway.com/lgmanuel/VisualCPP/GDICarSample.rar[^]
-
hi guys, am having problem with angle rotations.. i already have the formula, double fangle; double m_iAngle; m_iAngle = 45; POINT centerPt; centerPt.x = m_nCarX + 161; // which s is the x origin centerPt.y = y + 52; // which s is the y origin fangle = m_iAngle / 180. * 3.1415926; float OrX = (float)(centerPt.x - cos(fangle)*centerPt.x + sin(fangle)*centerPt.y); float OrY = (float)(centerPt.y - cos(fangle)*centerPt.y - sin(fangle)*centerPt.x); //tyre spoke dc.SelectStockObject(GRAY_BRUSH); dc.SelectObject(m_penTyreSpoke); for(int count = 0, count < 4, count++){ //spoke1 dc.MoveTo(m_nCarX + 161, y + 52); dc.LineTo(m_nCarX + 161, y + 41); } //see image here: http://h1.ripway.com/lgmanuel/Imgs/car.png[^] as you see in the image. the car's tire has only one spoke. am trying to loop the code to have 4 (four) spokes on my rim by bending the angle 90 DEGREES.. adding a 90 DEGREES on LOOP... //should look like this images bellow: http://h1.ripway.com/lgmanuel/Imgs/car-with-rim-spoke.png[^] help guys.. check the project bellow.. thanks ahead.. http://h1.ripway.com/lgmanuel/VisualCPP/GDICarSample.rar[^]
Hi, 1. first of all, are you on the right forum? have you switched from native C/C++ coding to managed C++/CLI coding all of a sudden? 2. please use PRE tags to show code snippets and do show the relevant code; nobody is going to download a ZIP/RAR file to help you out. 3. if you want N spokes, your best bet is using a for loop. They are pretty good at executing the same code over and over with a slight twist; and add 90 degrees to the angle each time. 4. Stop using all those magic constants (180, 3.1415926, 161, 52, 41). Either use a function parameter, use an object property (e.g. drawing size), use an official const such as Math.Pi, or if all else fails provide an actual const yourself. You will get more readable code with fewer errors. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.