绘制恒线速度的参数曲线

news/2024/7/8 12:40:56

假设一条参数曲线和某个参数 t 相关。
L:
   x  = f(t)
   y  = g(t)

如果我们绘制这条参数曲线的时候的,t是按比例增加的话。可能点的分布会不均匀。
那么按照什么公式来决定t的步长能让曲线的点分布均匀呢?

首先我们对参数曲线公式进行微分。

dx  = df(t)
dy  = dg(t)

那么 ds = sqrt( dx * dx + dy * dy)

于是 ds 跟 dt 的关系便建立起来了。

ds = sqrt( f'(t) * f'(t) + g'(t) * g'(t) ) * dt.
代入t = 0 跟 t=0时候的步长 dt(0)可以得到 t=0 时候ds(0) 。

根据需求。我们要保证以后每个dt(t)的值。 ds(t) = ds(0)
因此。得到

dt(t) = ds(0) / sqrt( f'(t) * f'(t) + g'(t) * g'(t) )
= dt(0) * sqrt( f'(0) * f'(0) + g'(0) * g'(0) ) / sqrt( f'(t) * f'(t) + g'(t) * g'(t) )

这样既可以绘制出等步长的恒线速度的参数曲线
 
例子椭圆


代码:

bool DrawEclips(float a , float b , HWND hWnd , HDC hdc)
{
     RECT rect ;
  GetClientRect(hWnd , &rect);
  int cx = rect.right/2;
  int cy = rect.bottom/2;
#define MYPI2 (3.1415926f*2.0f)
  float dtheta0 = 9.0f/360.0 * MYPI2;
  float theta = 0.0;
  float rt = MYPI2 / 1.5;
  for(;;)
  {
   float dtheta = b * dtheta0 / sqrt( a *a * sin(theta) * sin(theta) + b * b * cos(theta) * cos(theta) );
   float x = a * cos(theta);
   float y = b * sin(theta);
   int ix = cos(rt) *x - sin(rt)*y;
   int iy = sin(rt) *x + cos(rt)*y;
   ix += cx ;
   iy += cy ;
   if(theta >= MYPI2 ) break;
   SetPixel(hdc, (int)ix , (int)iy , RGB(255,0,255));
  
   theta += dtheta;
   if(theta > MYPI2 ) theta = MYPI2;
  }
  return 1;
}




http://www.niftyadmin.cn/n/3647800.html

相关文章

css遮罩mask_使用mask-image属性在CSS中遮罩图像

css遮罩maskWe covered the use of the clip-path property for clipping using CSS, so it’s only natural that we now go over masking. Contrary to clipping, where a part of an image or element is either completely invisible or completely visible, with masking …

css中让图片剪切居中_CSS中使用剪切路径进行剪切的简介

css中让图片剪切居中介绍 (Introduction) clip-path is a very interesting property that allows to clip the visible portion of SVG elements, images or any HTML element really. clip-path是一个非常有趣的属性,它允许剪切SVG元素,图像或任何HTML…

脚本与渲染器 .

一直以来都想做一个脚本驱动的渲染器.就是说可以用脚本定制渲染器的行为,比如创建多少个渲染队列,如何渲染.多少RenderTarget, 每个物体的材质也是一样. 要生成多少个Pass,每个Pass是立即渲染呢还是放到那个队列里 . 其实我是个很懒的人 ,这个想法早在去年就有了.一直拖到…

laravel入门_Laravel入门

laravel入门视频 (Video) 关于谈话 (About the Talk) Laravel — a free, open-source PHP web application framework — is one of the best ways to build web applications. It is a strong framework that gives many niceties out of the box, freeing you to create wit…

项目开发中源代码树的组织

很多人多很重视自己代码的可读性,重用性等,尽量让自己的代码看上去更加的雅观,因为很多人都认为这是代码优劣的门面光. 不过,我却认为,代码的门面光应该是源代码树的组织. 因为,别人看你的代码首先看到的目录结构.一个良好的目录结构,能很方便的让你定位到你需要的组…

css 垂直对齐_CSS垂直对齐属性

css 垂直对齐介绍 (Introduction) vertical-align defines the vertical alignment for the content of a table cell or for an inline element against the rest of the inline flow. vertical-align定义表格单元格的内容或内联元素相对于其余内联流的垂直对齐方式。 vertic…

一道智力题的数学解

最近看数学。都看的有点锈逗了。看到一道智力题,情不自禁的用数学来解了。。只是不知道结果对不对。题目: 已知:每个飞机只有一个油箱, 一箱油可供一架飞机绕地球飞180度。飞机之间可以相互加油(注意是相互&…

JavaScript Reduce方法介绍

介绍 (Introduction) Reduce is a method that can be difficult to understand especially with all the vague explanations that can be found on the web. There are a lot of benefits to understanding reduce as it is often used in state management (think Redux). 减…