- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 opengl 绘制空心椭圆。我使用标准椭圆公式计算 C++ 代码中的顶点。在片段着色器中,我只是为每个片段分配颜色。与曲线不那么尖锐的椭圆相比,我在屏幕上看到的椭圆在更尖锐的曲线上具有更细的线宽。那么问题来了,如何使整个椭圆参数的线宽一致呢?请看下图:
C++代码:
std::vector<float> BCCircleHelper::GetCircleLine(float centerX, float centerY, float radiusX, float radiusY, float lineWidth, int32_t segmentCount)
{
auto vertexCount = (segmentCount + 1) * 2;
auto floatCount = vertexCount * 3;
std::vector<float> array(floatCount);
const std::vector<float>& data = GetCircleData (segmentCount);
float halfWidth = lineWidth * 0.5f;
for (int32_t i = 0; i < segmentCount + 1; ++i)
{
float sin = data [i * 2];
float cos = data [i * 2 + 1];
array [i * 6 + 0] = centerX + sin * (radiusX - halfWidth);
array [i * 6 + 1] = centerY + cos * (radiusY - halfWidth);
array [i * 6 + 3] = centerX + sin * (radiusX + halfWidth);
array [i * 6 + 4] = centerY + cos * (radiusY + halfWidth);
array [i * 6 + 2] = 0;
array [i * 6 + 5] = 0;
}
return std::move(array);
}
const std::vector<float>& BCCircleHelper::GetCircleData(int32_t segmentCount)
{
int32_t floatCount = (segmentCount + 1) * 2;
float segmentAngle = static_cast<float>(M_PI * 2) / segmentCount;
std::vector<float> array(floatCount);
for (int32_t i = 0; i < segmentCount + 1; ++i)
{
array[i * 2 + 0] = sin(segmentAngle * i);
array[i * 2 + 1] = cos(segmentAngle * i);
}
return array;
}
最佳答案
问题很可能是您的片段基本上是从椭圆中心向外辐射的线段。
如果你画一条线,从椭圆的中心穿过你画的椭圆,在周长上的任何一点,你可能会说服自己,那条红线所覆盖的距离实际上就是你所画的宽度之后(粗略地说,因为您在低空间分辨率下工作;有些像素化)。但由于这是一个椭圆,该距离并不垂直于所追踪的路径。这就是问题所在。这对圆非常有用,因为来自中心的射线总是垂直于圆。但是对于这些扁平的椭圆来说,它是非常倾斜的!
如何解决?你能在椭圆上的每个点画圆而不是线段吗?
如果不是,您可能需要重新计算在那个倾斜角度测量时那么厚意味着什么 - 它不再是您的线宽,可能需要一些微积分和更多三角函数。
好的,所以一个 vector 与由
描述的曲线相切c(i) = (a * cos(i), b * sin(i))
是
c'(i) = (- a * sin(i), b * cos(i))
(注意这不是单位 vector )。与此垂直的是
c'perp = (b * cos(i), a * sin(i))
您应该能够通过计算他们的点积说服自己这是真的。
让我们计算 c'perp
的大小, 并称之为 k
现在:
k = sqrt(b * b * cos(i) * cos(i) + a * a * sin(i) * sin(i))
所以我们走到椭圆 (c(i)) 上的一个点,我们想要绘制一条垂直于曲线的线段 - 这意味着我们想要添加一个缩放版本的 c'perp
.缩放比例是除以幅度(k
),然后乘以线宽的一半。所以两个端点是:
P1 = c(i) + halfWidth * c'perp / k
P2 = c(i) - halfWidth * c'perp / k
我还没有测试过这个,但我很确定它很接近。这是您正在使用的几何体:
--编辑:
因此 P1
的值和 P2
我上面给出的是垂直于椭圆的线段的端点。如果你真的想继续只是改变 radiusX
和 radiusY
重视你做事的方式,你可以做到这一点。您只需要弄清楚每个角度的“Not w”长度是多少,然后使用该值的一半代替 halfWidth
在 radiusX +/- halfWidth
和 radiusY +/- halfwidth
.我将那部分几何知识留给读者作为练习。
关于c++ - 椭圆的线宽不是常数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38986938/
我不明白基因编程的人工智能是如何实现的。可以确定最终方程中何时应该有一个常数。如果我采用公式 F(m) = ma; F(m) = m9.8,A.I.知道真正的数字 9.8 到底是多少吗?据我了解,您实
我的批次大小是可变的,所以我的所有输入都是以下形式 tf.placeholder(tf.float32, shape=(None, ...) 接受可变的批量大小。但是,如何创建具有可变批处理大小的常数
我有一个一维 Numpy 数组 A长度N .对于每个元素 x在数组中,我想知道数组中所有元素在[x-eps]范围内的比例是多少; x+eps ],其中 eps是一个常数。 N数量级为 15,000。
如果我像这样在文件中设置一些常量: 'use strict'; angular.module('balrogApp.config', []) .constant('balrogConfig',
谁能给我一个常量 r 值的例子? 因为显然即使文字也是右值而不是常量右值。 最佳答案 const T f(); 根据该定义,表达式 f() 是 const T 类型的右值表达式,即常量右值。 关于c+
我正在开发一个 Angular 应用程序,我想创建一个配置文件。根据我的阅读,我应该使用 Angular 常数。 所以我尝试创建我的常量。从我读到的内容( here , here 以及 here +
const int N = 100; void function1(int array[]){ // ... } void function2(int arra
考虑以下(工作)片段: Eigen::ArrayXd x (8); x > y (x.data(), 2, 4); 这也是可行的: const Eigen::ArrayXd const_x = x;
我知道你可以使用: #define _USE_MATH_DEFINES 然后: M_PI 得到常量 pi。但是,如果我没记错的话(欢迎评论)这是编译器/平台相关的。那么,当我将 pi 常量从 Linu
为什么这段代码无法编译? package main const a = 1.000001 const base = 0 const b = a+base func main() { f(b)
为什么下面的代码每条语句都引用了大O常量(这里我为了约定使用1)? 我的意思是,如果数组大小变大,时间复杂度可能会变大,对吗?而且总数会越来越大,会不会影响复杂度? 伪代码: def find_sum
我正在尝试创建一个函数来填充多个系列中缺失的数字,具有不同的数字比例,同时为每个系列生成一个常量列。 from tika import parser import pandas as pd impor
我正在尝试近似 e 的值(~2.7) 由此定义,对于每个第 n 项 在Python中使用递归函数。 到目前为止我已经得到了这个, def NapierConstant(runs): retur
系统提示我输入代码以某种方式打印 Champerowne 常量系列。 (实际使用它!)所以我们想找到这个系列的第 n 个数字:1234567891011121314...这是我的代码: #inclu
我正在学习硕士定理的期中考试,我遇到了案例 2 的示例,其中 k > 0。除了常数及其递增或计算方式之外,我了解有关定理的所有内容。 Case 2状态:T(n) = Θ(nlogba logk+1n)
问题实例:无向无权图 G=(V,E)。两个源节点a和b,两个目的节点c和d以及一个常数D(完全正数)。(我们可以假设lambda(c,d),lambda(a,b)>D,当lambda(x,y ) 是
我有一张很大的 table 。 它目前在 MySQL 数据库中。 我使用django。 我需要迭代 每个表的元素来预先计算一些特定的数据(也许如果我更好的话,我可以这样做,但这不是重点)。 我想在不断
VBScript 常数 常数是具有一定含义的名称,用于代替数字或字符串,其值从不改变。VBScript 定义了许多内部常数。详细信息,请参阅 VBScript 语言参考。 创建常数 您可以使用
我正在学习 javascript,我发现一个文件中有许多用操作数“:”而不是“=”完成的赋值。尽管问题的标题是这样,但我也在非常量中看到过它。那有什么意义呢?这里的“:”操作数是什么意思?谢谢。 v
鉴于应用程序启动: angular.module("starter", [ "ionic" ]) .constant("DEBUG", true) .run(function() {
我是一名优秀的程序员,十分优秀!